Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 07-10-2005, 06:11 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Merging 2 Arrays

I have 2 arrays, I want to merge them on the common intersect.

Here they are...
Code:
Array
(
    [0] => Array
        (
            [countm] => 16
            [percentage] => 84.2%
            [gamename] => Battlefield 2
        )

    [1] => Array
        (
            [countm] => 1
            [percentage] => 5.3%
            [gamename] => Call of Duty
        )

    [2] => Array
        (
            [countm] => 0
            [percentage] => 0%
            [gamename] => Command & Conquer
        )

    [3] => Array
        (
            [countm] => 17
            [percentage] => 89.5%
            [gamename] => Counter Strike
        )

    [4] => Array
        (
            [countm] => 0
            [percentage] => 0%
            [gamename] => Counter Strike- Condition Zero
        )

    [5] => Array
        (
            [countm] => 1
            [percentage] => 5.3%
            [gamename] => Counter Strike- Source
        )

    [6] => Array
        (
            [countm] => 4
            [percentage] => 21.1%
            [gamename] => Day of Defeat
        )

    [7] => Array
        (
            [countm] => 0
            [percentage] => 0%
            [gamename] => Diablo II
        )

    [8] => Array
        (
            [countm] => 6
            [percentage] => 31.6%
            [gamename] => Diablo II- Lord of Destruction
        )

    [9] => Array
        (
            [countm] => 0
            [percentage] => 0%
            [gamename] => Final Fantasy XI
        )

    [10] => Array
        (
            [countm] => 0
            [percentage] => 0%
            [gamename] => Gun Bound
        )

    [11] => Array
        (
            [countm] => 2
            [percentage] => 10.5%
            [gamename] => Maple Story
        )

    [12] => Array
        (
            [countm] => 0
            [percentage] => 0%
            [gamename] => Rune Scape
        )

    [13] => Array
        (
            [countm] => 0
            [percentage] => 0%
            [gamename] => Soldat
        )

    [14] => Array
        (
            [countm] => 2
            [percentage] => 10.5%
            [gamename] => StarCraft
        )

    [15] => Array
        (
            [countm] => 4
            [percentage] => 21.1%
            [gamename] => StarCraft- Brood War
        )

    [16] => Array
        (
            [countm] => 0
            [percentage] => 0%
            [gamename] => WarCraft III
        )

    [17] => Array
        (
            [countm] => 1
            [percentage] => 5.3%
            [gamename] => WarCraft III- Frozen Throne
        )

    [18] => Array
        (
            [countm] => 4
            [percentage] => 21.1%
            [gamename] => World of Warcraft
        )

)
Array
(
    [0] => Array
        (
            [countc] => 8
            [gamename] => Battlefield 2
        )

    [1] => Array
        (
            [countc] => 8
            [gamename] => Call of Duty
        )

    [2] => Array
        (
            [countc] => 5
            [gamename] => Command & Conquer
        )

    [3] => Array
        (
            [countc] => 25
            [gamename] => Counter Strike
        )

    [4] => Array
        (
            [countc] => 8
            [gamename] => Counter Strike- Condition Zero
        )

    [5] => Array
        (
            [countc] => 12
            [gamename] => Counter Strike- Source
        )

    [6] => Array
        (
            [countc] => 17
            [gamename] => Day of Defeat
        )

    [7] => Array
        (
            [countc] => 7
            [gamename] => Diablo II
        )

    [8] => Array
        (
            [countc] => 15
            [gamename] => Diablo II- Lord of Destruction
        )

    [9] => Array
        (
            [countc] => 9
            [gamename] => Gun Bound
        )

    [10] => Array
        (
            [countc] => 7
            [gamename] => Maple Story
        )

    [11] => Array
        (
            [countc] => 5
            [gamename] => Rune Scape
        )

    [12] => Array
        (
            [countc] => 10
            [gamename] => Soldat
        )

    [13] => Array
        (
            [countc] => 15
            [gamename] => StarCraft
        )

    [14] => Array
        (
            [countc] => 3
            [gamename] => StarCraft- Brood War
        )

    [15] => Array
        (
            [countc] => 5
            [gamename] => WarCraft III
        )

    [16] => Array
        (
            [countc] => 8
            [gamename] => WarCraft III- Frozen Throne
        )

    [17] => Array
        (
            [countc] => 8
            [gamename] => World of Warcraft
        )

)
I want to create an array foreach game that has
countc, countm, gamename, and percentage (in the same format as it is now, just one array instead of 2).

I tried using nested foreachs using IFs to create a new array, but had no luck, it just got really messy.

Any help would be greatly appreciated.

If it is something extremely simple, I apologize, I was up way too last last night working on this. :ermm:
Reply With Quote
  #2  
Old 07-10-2005, 08:50 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have a look at 'array_merge'
Reply With Quote
  #3  
Old 07-10-2005, 09:07 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That just adds the second one to the end of the first. I need it kind of like a left join in MySQL. Both have a common field, combine resultset with only one of the common field.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:42 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05520 seconds
  • Memory Usage 2,183KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete