PHP array_unshift () Modify array key considerations _php Tips

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.