PHP inserts a function of one or more elements into the end of an array array_push ()

Source: Internet
Author: User

Parameter instance

Insert "blue" and "yellow" to the tail of the array:

<?php$a=array ("Red", "green"), Array_push ($a, "blue", "yellow");p rint_r ($a); >

Definition and usage

The Array_push () function inserts one or more elements into the tail of the array.

Tip: You can add one or more values.

Note: Even if your array has a string key name, the element you are adding will be a numeric key name (see the following example).

Grammar

Array_push (Array,value1,value2 ...)
parameters description
array required. Specifies an array.
value1 required. Specifies the value to add.
value2 optional. Specifies the value to add.

Technical details

return value: Returns the number of elements of the new array.
PHP version: 4 +

More examples

Example 1

An array with the string key name:

<?php$a=array ("A" and "Red", "b" = "green"), Array_push ($a, "blue", "yellow");p rint_r ($a); >

Example One

Use the PHP Array_push () function to insert "blue" and "yellow" at the end of the array with the following code:

<?php$a=array ("Red", "green"), Array_push ($a, "blue", "yellow");p rint_r ($a); >

Code Run Result:

Related Article

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.