This article analyzes the Array_unshift () in PHP to modify array key considerations. Share to everyone for your reference, specific as follows:
As we all know, Array_unshift () is used to add elements to the beginning of an array, but today it suddenly turns out that if the key value of an array is a numeric type (or can be converted to a numeric type), Array_unshift () modifiesthe key of all elements that are numeric.
Instance:
$a =array (111=> "dddddddddddd", "112" =>array ("one" => "Orange", "two" => "Hhhhh"), "113" =>array ("one" = > "Orange", "two" => "Hhhhh"), "Oooo" => "JJJJJ");
Print_r ($a); echo "</br>";
Array_unshift ($a, "aaaaaaaaa");
Print_r ($a); echo "</br>";
Output results:
Array ([a] => dddddddddddd [112] => Array ([one] => Orange [two] => hhhhh) [113] => Array ([one] => ; Orange [two] => hhhhh) [oooo] => jjjjj)
Array ([0] => aaaaaaaaa [1] => dddddddddddd [2] => Array ([ One] => Orange [two] => hhhhh) [3] => Array ([one] => Orange [two] => hhhhh) [oooo] => JJJJJ)
See, Array_unshift () after the array key value has changed, the original 111 into 1, really pits! In the future, when you use Array_unshift (), you need to pay special attention to this!
Add: Small knitting here recommend a site for the layout of the PHP format landscaping tools to help you in the future of PHP programming code layout:
PHP Code online Format Landscaping tool:Http://tools.jb51.net/code/phpformat
More about PHP Interested readers can view the site topics: "PHP array" Operation tips Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Mathematical Calculation Skills Summary, "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.