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, ∼2943🔥, 0💬
Popular Posts:
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...
How to attach console to a Running Container using the "docker container exec" command? I want to ge...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...
How to troubleshoot the Orderer peer? The Docker container terminated by itself. You can follow this...
How to add request URL Template Parameters to my Azure API operation 2017 version to make it more us...