Php array shift
From w3cyberlearnings
Contents |
PHP function array_shift
This function returns the first array element, and it removes the first array element from the origional array.
Syntax array_shift
- array: array input
array_shift(array);
Note
Use array_pop() to remove the last array element.
Example 1
<?php $records = array('John', 'Zahra', 'Omari'); $first_element = array_shift($records); echo $first_element; ?>
Output
John
Example 2
<?php $records = array('John', 'Zahra', 'Omari'); $first_element = array_shift($records); print_r($records); ?>
Output
Array ( [0] => Zahra [1] => Omari )
Example 3
<?php $test = array('job' => 32, 'apple' => 'orange', 'pen' => 'paper'); $return =array_shift($test); print_r($return); ?>
Output
32
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys