Tools, FAQ, Tutorials:
Copying an Array in PHP
Can You Copy an Array in PHP?
✍: FYIcenter.com
You can create a new array by copying an existing array using the assignment statement. Note that the new array is not a reference to the old array. If you want a reference variable pointing to the old array, you can use the reference operator "&". Here is a PHP script on how to copy an array:
<?php $oldArray = array("Zero"=>"PHP", "One"=>"Perl", "Two"=>"Java"); $newArray = $oldArray; $refArray = &$oldArray; $newArray["One"] = "Python"; $refArray["Two"] = "C#"; print("\$newArray[\"One\"] = ".$newArray["One"]."\n"); print("\$oldArray[\"One\"] = ".$oldArray["One"]."\n"); print("\$refArray[\"Two\"] = ".$refArray["Two"]."\n"); print("\$oldArray[\"Two\"] = ".$oldArray["Two"]."\n"); ?>
This script will print:
$newArray["One"] = Python $oldArray["One"] = Perl $refArray["Two"] = C# $oldArray["Two"] = C#
⇒ Looping through an Array in PHP
⇐ Adding Values to an Array without Keys in PHP
2017-02-03, 2475🔥, 0💬
Popular Posts:
How To Copy Array Values to a List of Variables in PHP? If you want copy all values of an array to a...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...
How to use the JSON to XML Conversion Tool at utilities-online.info? If you want to try the JSON to ...
What are the differences of Differences of evaluateTransaction() and submitTransaction() of the fabr...
What is EPUB 2.0 Metadata "dc:creator" and "dc:contributor" elements? EPUB 2.0 Metadata "dc:creator"...