Merging Arrays
| From: | W-Mark Kubacki | Date: | Fri, 22 Feb 2002 18:59:51 +0000 |
| Subject: | Merging Arrays | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-12230@lists.php.net to get a copy of this message | ||
Hello,
I'm trying to merge two multidimensional arrays, but it
doesn't work neither with array_merge nor array_merge_recursive.
Is there a solution which makes the following problem-script
to print every element (and not mergin two existing elements
to a new sub-array):
--------------------- Code ---------------------------------------
// Array-merging
$test['main']['sector']['seting'] = 'seting1';
$test['main']['sector']['config'] = 'config1';
$test['main']['mysql'] = 'dbsql1';
$test['main'][0][1] = '01_1';
$test['main'][0][2] = '02_1';
$test['main'][1][0] = '10_1';
$test['sub']['wmk'] = 'wmk1';
$zwo['det'] = 'det2';
$zwo['main']['sector']['config'] = 'config2';
$zwo[2] = '2';
$zwo['main']['fddb'] = 'fddb2';
$new = array_merge_recursive($test, $zwo);
echo($new['main']['sector']['seting']." x<br>\n");
echo($new['main']['sector']['config']." x<br>\n");
echo($new['main']['mysql']." x<br>\n");
echo($new['main'][0][1]." x<br>\n");
echo($new['main'][0][2]." x<br>\n");
echo($new['main'][1][0]." x<br>\n");
echo($new['sub']['wmk']." x<br>\n");
echo($new['det']." x<br>\n");
echo($new[2]." x<br>\n");
echo($new['main']['fddb']." x<br>\n");
------------------------------------------------------------------
Thanks,
Mark