Php array reverse
From w3cyberlearnings
Contents |
PHP function array_reverse
This function reverses array.
Syntax array_reverse
- array: array input
- bool (option): TRUE (preserved the numeric keys)
array_reverse(array, bool);
Example 1
<?php $person = array('giant','emissions','news','animals'); $r = array_reverse($person); print_r($r); ?>
Output
Array ( [0] => animals [1] => news [2] => emissions [3] => giant )
Example 2: preserved the keys
<?php $person = array('giant','emissions','news','animals'); $r = array_reverse($person,true); print_r($r); ?>
Output
Array ( [3] => animals [2] => news [1] => emissions [0] => giant )
Example 3
<?php $list = array('apple' => 'dog', 3 => 'great', 'love'); $new_list = array_reverse($list); print_r($new_list); ?>
Output
Array ( [0] => love [1] => great [apple] => dog )
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