PHP array elements are added to the array header (Array_unshift usage)

Source: Internet
Author: User

Using the PHP built-in function array_unshift, the following is an enumeration of the use of the Array_unshift function.

Array_unshift

The function is to insert one or more elements at the beginning of the array. Added elements as a whole add the same order of elements in the array as in the parameters. All the numeric key names in the modified array are modified to count from zero, and all the text keys remain unchanged. The function returns the number of elements in the array after the operation.

Syntax: int array_unshift (array & $array, mixed $var [, mixed $ ...])

For example:

The code is as follows Copy Code

<?php

$queue = Array ("111cn.net", ". com");

Array_unshift ($queue, "apple", "raspberry");

Print_r ($queue);

The above routines will output:

Array
(
[0] => Apple
[1] => Raspberry
[2] => 111cn.net
[3] =>. com
)

Of course we can use other methods directly, such as creating an array and assigning him a value.

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.