Multidimensional arrays copy..

From: Date: Sun, 12 Sep 2004 23:44:38 +0000
Subject: Multidimensional arrays copy..
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969364016@lists.php.net to get a copy of this message
Hello, phpdoc@lists.php.net Seems, that multidimensional arrays are copied with one dimension, which contains references to other included arrays. I haven't found any references in manual, so this should be stated somewhere and link provided on foreach page and maybe other functions, which work with array copy. Perhaps I could do it myself, but I don't feel so. Consider the following sample. --- <?php $a[0]['id'] = array(22, 12, 33, 55); $a[0]['secid'] = array("a","b","c","d"); print_r($a); $b = $a; foreach ($b as $k => $v) { array_multisort($v['id'], SORT_DESC, $v['secid'], SORT_DESC); } print_r($a); ?> --- I was surprised when I've found my $a sorted. Solution how to pass around this feature, since there's no array_copy() function in PHP. $b = unserialize( serialize( $a ) ); t -- --[ http://wiki.phpdoc.info/DocLinks ]--

« previous php.doc (#969364016) next »