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, 2119🔥, 0💬
Popular Posts:
Can Two Forms Be Nested? Can two forms be nested? The answer is no and yes: No. You can not nest two...
How to convert a JSON text string to an XML document with PHP language? Currently, there is no built...
What Is session_register() in PHP? session_register() is old function that registers global variable...
How To Change Text Fonts for Some Parts of a Paragraph? If you want to change text fonts or colors f...
How To Submit Values without Using a Form in PHP? If you know the values you want to submit, you can...