note 92232 added to language.operators.array

From: Date: Wed, 15 Jul 2009 07:51:55 +0000
Subject: note 92232 added to language.operators.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-158321@lists.php.net to get a copy of this message
What about array addition, if the array elements are multidimensional arrays? $array1 = array( array('id'=>1,'name'=>'John'), array('id'=>2,'name'=>'Fritz') ); $array2 = array( array('id'=>4,'name'=>'Emma'), array('id'=>7,'name'=>'Johanna') ); if i try array_merge or $array1 + $array2 the result only contains the value of the first array. What i want to have is simply one array with all element of both arrays like that array(4) { [0]=> array(2) { ["id"]=> int(1) ["name"]=> string(4) "John" } [1]=> array(2) { ["id"]=> int(2) ["name"]=> string(5) "Fritz" } [2]=> array(2) { ["id"]=> int(4) ["name"]=> string(4) "Emma" } [3]=> array(2) { ["id"]=> int(7) ["name"]=> string(7) "Johanna" } } i get this if i do something like that foreach( $array2 as $value ) { $array1[] = $value; } is there any better or easier way to get the goal? THX in advanced mav ---- Server IP: 69.147.83.197 Probable Submitter: 141.16.127.38 ---- Manual Page -- http://www.php.net/manual/en/language.operators.array.php Edit -- https://master.php.net/note/edit/92232 Del: integrated -- https://master.php.net/note/delete/92232/integrated Del: useless -- https://master.php.net/note/delete/92232/useless Del: bad code -- https://master.php.net/note/delete/92232/bad+code Del: spam -- https://master.php.net/note/delete/92232/spam Del: non-english -- https://master.php.net/note/delete/92232/non-english Del: in docs -- https://master.php.net/note/delete/92232/in+docs Del: other reasons-- https://master.php.net/note/delete/92232 Reject -- https://master.php.net/note/reject/92232 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158321) next »