PHP Array function sequence Array_push array tail add one or more elements (into the stack), return the new length.

Source: Internet
Author: User
Array_push () Definition and usage
The Array_push () function adds one or more elements (into the stack) to the end of the array of the first parameter, and then returns the length of the new array.
The function equals multiple calls $array [] = $value.
Grammar
Array_push (Array,value1,value2 ...) Parameter description
Array required. Specifies an array.
Value1 required. Specifies the value to add.
value2 is optional. Specifies the value to add.
Hints and Notes
Note: Even if there are string key names in the array, the elements you add are always numeric keys. (see Example 2)
Note: If you use Array_push () to add a cell to an array, you might as well use $array [] =, because there is no additional burden of calling the function.
Note: If the first parameter is not an array, Array_push () will issue a warning. This differs from the behavior of the $var [], which creates a new array.
Example 1

The code is as follows:

<?php $a =array ("Dog", "Cat"); Array_push ($a, "Horse", "Bird"); Print_r ($a);?>

Output:
Array ([0] = Dog [1] = Cat [2] = = Horse [3] = = Bird)

Example 2
An array with a string key:

The code is as follows:

<?php $a =array ("a" and "Dog", "b" = "Cat"); Array_push ($a, "Horse", "Bird"); Print_r ($a);?>

Output:
Array ([A] = Dog [b] = Cat [0] = = Horse [1] = = Bird)

The above describes the PHP array function sequence Array_push array tail add one or more elements (into the stack), return the new length. , including the aspects of the content, want to be interested in PHP tutorial friends helpful.

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