Hi all,
I've been digging through the documentation, butting my head against the wall, etc., and still haven't found a good solution to the following problem:
I have two arrays, $array1 and $array2, which print_r displays as follows:
Array 1:
Array
(
[foo] =>
[bar] =>
)
Array 2:
(
[0] => Array
(
[name] => foo
[value1] => 1
[value2] => 2
)
[1] => Array
(
[name] => foo
[value1] => 3
[value2] => 4
)
[2] => Array
(
[name] => bar
[value1] => 1
[value2] => 2
)
)
I would like to merge these arrays where $array2[name] equals the keys of $array1, so that print_r($array3) yeilds:
Array 3:
Array
(
[foo] => Array
(
[0] = Array
(
[value1] = 1
[value2] = 2
)
[1] = Array
(
[value1] = 3
[value2] = 4
)
)
[bar] => Array
(
[0] = Array
(
[value1] = 1
[value2] = 2
)
)
)
This would be simple if I could push key=>value pairs onto an array where 'value' is itself an array, something like:
$baz = array();
$keys = array("foo", "bar");
foreach ($keys as $key) {
array_push($baz, $key => array("x", "y", "z"));
}
but according to the docs that isn't possible with array_push. Does anyone know a workaround?
Apologies if the above is unclear/moronic, and thanks in advance.
John