PHP-delete array kinsoku elements

Source: Internet
Author: User

Delete a cell element at the beginning

Array_shift

(PHP 4, PHP 5)

Array_shift - moves the cell at the beginning of the array to the group

Description

Array_shift   (   array   & $array   )

arra Y_shift ()   will   array   is moved out and returned as a result,   array   the length minus all the other units moving forward one bit. All numeric key names are changed from zero to start, and the text key name is unchanged.

Note: Using this function resets the (reset())array pointer.

Parameters
    • array

    • The input array.

return value

Returns the value that is moved out if array it NULL is empty or not an array.

Example

Example #1 array_shift () Example

<?php
$stack= Array ("Orange", "Banana", "Apple", "Raspberry");
$fruit= Array_shift($stack);
Print_r($stack);
?>

The above routines will output:

Array ([0] = banana [1] = Apple [2] = raspberry)

and Orange was assigned to it $fruit .




Delete Trailing cell elements



Array_pop

(PHP 4, PHP 5)

Array_pop - pops the last element of the array (out of the stack)

Description

Mixed array_pop ( array ) &$array

Array_pop () Eject and return array The last cell of the array, and the array array Of the length minus one. If array Empty (or not an array) will return NULL。 Also, if the call is not a number, it will produce a Warning.

Note: Using this function resets the (reset())array pointer.

Parameters
    • array

    • You need to make an array of stacks.

return value

array returns the last value. If array NULL It is empty (if it is not an array), it will be returned.

Example

Example #1 array_pop () Example

<?php
$stack= Array ("Orange", "Banana", "Apple", "Raspberry");
$fruit= Array_pop($stack);
Print_r($stack);
?>

After this operation, $stack There will be only 3 units:

Array ([0] = orange [1] = banana [2] = apple)

and rasberry will be assigned to $fruit .


This article from "I am a phper, simple and naïve" blog, please be sure to keep this source http://thinkforphp.blog.51cto.com/8733331/1784640

PHP-delete array kinsoku elements

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.