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, ∼3376🔥, 0💬
Popular Posts:
How to use "json-to-xml" Azure API Policy Statement? The "json-to-xml" Policy Statement allows you t...
How to use the "set-body" Policy Statement for an Azure API service operation? The "set-body" Policy...
How to decode the id_token value received from Google OpenID Connect authentication response? Accord...
How to Instantiate Chaincode on BYFN Channel? You can follow this tutorial to Instantiate Chaincode ...
How to dump (or encode, serialize) a Python object into a JSON string using json.dumps()? The json.d...