array_shift and array_unshift

array_shift and array_unshift

array_shift:
========

array_shift
- It  shift an element off the beginning of array

Syntax:
=====
mixed array_shift ( array array)

array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. If array is empty (or is

not an array), NULL will be returned.

Example:
=======

$arr1 = array (”10″, “20″, “30″, “40″);
$arr2 = array_shift ($arr1);

This would result in $arr1 having 3 elements left: Array
(
[0] => 20
[1] => 30
[2] => 40
)
The result in $arr2  Array
(
[0] => 10
)

array_unshift:
==========

array_unshift

- It  append one or more elements to the beginning of array

Syntax:
=====
int array_unshift ( array array, mixed var [, mixed …])

array_unshift() prepends passed elements to the front of the array. Note that the list of elements is prepended as a whole, so that the prepended elements

stay in the same order.

Returns the new number of elements in the array.

Example:
======

$arr1 = array (”10″, “20″);
array_unshift ($arr1, “30″, “40″);

This would result in $arr1 having the following elements: Array
(
[0] => 30
[1] => 40
[2] => 10
[3] => 20
)

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.