note 60954 deleted from language.types.array by nforbes
| From: | nforbes@php.net | Date: | Fri, 18 Aug 2006 21:58:53 +0000 |
| Subject: | note 60954 deleted from language.types.array by nforbes | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116049@lists.php.net to get a copy of this message | ||
Note Submitter: Simon Rigét at paragi.dk
----
Make a real copy of an array.
One simple way is to use array_diff function.
<?php
// Define a multidimentional array
$arr1['color']=array('red','green','blue');
$arr1['number']=array(1,2,3);
// Copy all by getting the differance between this and an empty array.
$arr2=array_diff($arr1,array());
// To show that its not a reference, delete the original and display the content of the new array.
unset($arr1);
var_dump($arr2);
?>
Output:
array(2) {
["color"]=> array(3) {
[0]=> string(3) "red"
[1]=> string(5) "green"
[2]=> string(4) "blue"
}
["number"]=> array(3) {
[0]=> int(1)
[1]=> int(2)
[2]=> int(3)
}
}