vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Merging 2 Arrays (https://vborg.vbsupport.ru/showthread.php?t=91937)

Adrian Schneider 07-10-2005 05:11 PM

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:

Marco van Herwaarden 07-10-2005 07:50 PM

Have a look at 'array_merge'

Adrian Schneider 07-10-2005 08:07 PM

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.


All times are GMT. The time now is 03:43 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01579 seconds
  • Memory Usage 1,743KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete