Use array_push (1) for PHP array processing functions)

Source: Internet
Author: User
The use of the PHP array processing function array_push (1) will involve a lot of array operations when using PHP for data processing. here I will write down the use of various array processing functions, so it is better to remember it !!

I. how to use array_push: push one or more units to the end of the array (into the stack)

Description: Int array_push (array & $ array, mixed $ var [, mixed $...])Parameter description: Array is the value to be pushed into the input array $ var.

Here, mixed indicates that this parameter can be of different (but not necessarily all) types.

Array_push () treats array as a stack and pushes the passed variables to the end of array. The length of array increases according to the number of variables in the stack. The effect is the same as the following:

$ Array [] = $ var;
?>
Repeat the preceding actions for each var, which is equivalent to performing multiple value assignment operations on $ array.

Return value:Returns the number of processed array elements.

Note:(1) If array_push () is used to add a unit to the array, it is better to use $ array [] = (assign values directly to the array) because there is no additional burden to call the function.

(2) If the first parameter is not an array, array_push () will issue a warning. This is different from the behavior of $ var []. The latter creates an array.

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.