PHP array_push () function example tutorial and usage

Source: Internet
Author: User

PHP array_push () function example tutorial and usage

Definition and usage
This array_push () function inserts an array at the end of one or more elements.

Syntax

Array_push (array, value1, value2 ...)
  

Parameter description
Array required. Specify an array
Value1 requirement. The specified value is increased.
Value2 is optional. The specified value is increased.

Tips and instructions
Tip: you can add a value or as many as you like.

Note: Even if you already have a string array key, your supplemental content will have a number key in allways. (See example 2)

 

 

<? Php $ a = array ("Dog", "Cat"); array_push ($ a, "Horse", "Bird"); print_r ($ a);?>
 
Output result.
Array ([0] => Dog [1] => Cat [2] => Horse [3] => Bird)
 
Let's look at an instance.
 
      

Arrays and string items:

 

 

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

 

 

 

 

Output

Array ([a] => Dog [B] => Cat [0] => Horse [1] => Bird)

Let's see an instance.

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.