0

Thanks for helping as always.

My code generates arrays in the following format

${'readyformerge' . $b} = $temparraytwo;

Which results in the array names of

$readyformerge1
$readyformerge2
$readyformerge3

etc...

Which works well and we know the value that $b holds is the amount of arrays we need to merge. However I can't quite see how to do this when we won't know prior to running the script how many arrays will be created.

Fundamentally I would like to use the following to grab the result but as you see I can only do this for the amount of results I THINk it will return NOT the actual number of results. Any help?

$outputmultidimensionalevent = array_merge_recursive(${'readyformerge' . $b},${'readyformerge' . $b});
print_r($outputmultidimensionalevent); echo '<br/>';

2 Answers 2

2

Your problem is the result of bad design.

Instead of:

${'readyformerge' . $b} = $temparraytwo;

You should do something like this:

$readyformerge[$b] = $temparraytwo;

And then:

$merged = array();

foreach ($readyformerge as $one) {
    $merged = array_merge($merged, $one);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @bodgan, I've explained slightly further below. You have certainly pointed me in the right direction so far!
0

Thanks, That's pushed me in the right direction.

So currently it's now setup like this:

    $z=1;
    $readyformergemulti = array();
    while ($z <= $i){
    array_push($readyformergemulti,${'readyformerge' . $z});
    $z++;
    }
    foreach ($readyformergemulti as $one) {
        print_r($one);
        echo '<br/>';
    $merged = array_merge_recursive($merged, $one);
    }
    print_r($readyformergemulti); echo '<br/>';
    print_r($merged); echo '<br/>';

But unfortunately $merged returns nothing. If you look at the following the first 4 lines are the $readyformerge arrays and the 5th line is the desired result:

Array ( [house] => 2797 ) 
Array ( [house] => 2829 ) 
Array ( [house] => 2736 )
Array ( [electronica] => 2763 [house] => 2763 ) 
Array ( [electronica] => Array (2763) [house] => Array (2763,2797,2892,2736 ) )

Sorry to be a pain, and I KNOW everyone needs to see more code, but with thousands of lines it gets hard to display!

If you can help again that would be great!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.