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#
2017-02-03, 1262👍, 0💬
Popular Posts:
Where is API Management Service on my Azure Portal? If your IT department has signed up for an Azure...
How to use urllib.parse.urlencode() function to encode HTTP POST data? My form data has special char...
FYIcenter JSON Validator and Formatter is an online tool that checks for syntax errors of JSON text ...
How To Control Padding Spaces within a Table Cell? Cell padding spaces are spaces between cell inner...
How to use "link" command tool to link objet files? If you have object files previously compiled by ...