PHP Array function sequence Array_unshift () inserts one or more elements at the beginning of the array _php tutorial

Source: Internet
Author: User
Array_unshift () Definition and usage
The Array_unshift () function inserts one or more elements at the beginning of the array.

The added elements, as a whole, are in the order of the elements in the array and in the order of the parameters.

The function returns the number of elements in the array.

Grammar
Array_unshift (Array,value1,value2,value3 ...) Parameter description
Array required. Specifies the input array.
Value1 required. Specifies the value to insert.
value2 is optional. Specifies the value to insert.
Value3 is optional. Specifies the value to insert.

Hints and notes
Note: All numeric key names are modified to count back from zero, and all string key names remain unchanged.

Example 1
Copy CodeThe code is as follows:
$a =array ("a" and "Cat", "b" = "Dog");
Array_unshift ($a, "Horse");
Print_r ($a);
?>

Output:

Array ([0] = Horse [A] = Cat [b] = Dog) Example 2
Return key value:
Copy CodeThe code is as follows:
$a =array ("a" and "Cat", "b" = "Dog");
Print_r (Array_unshift ($a, "Horse"));
?>

Output:

3 Example 3
Array with numeric keys:
Copy CodeThe code is as follows:
$a =array (0=> "Cat",1=> "Dog");
Array_unshift ($a, "Horse");
Print_r ($a);
?>

Output:

Array ([0] = Horse [1] = Cat [2] = Dog)

http://www.bkjia.com/PHPjc/324613.html www.bkjia.com true http://www.bkjia.com/PHPjc/324613.html techarticle Array_unshift () defines and uses the Array_unshift () function to insert one or more elements at the beginning of the array. The added elements as a whole add, the order of these elements in the array and the ...

  • 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.