PHP reverse array and replacement array key and value explanation reverse array element order array_reverse () function reverse the order of elements in the array. The format is as follows :? Arrayarray_reverse (arrayarray [, booleanpreserve_keys])? If the optional parameter preserve_keys is set to TRUE, key ING is maintained. Otherwise, the reset values correspond to the previous PHP reverse array and replacement array keys and values.
Reverse array element order
The array_reverse () function reverses the order of elements in the array. The format is as follows:
?
array array_reverse(array array [, boolean preserve_keys])
?
If the optional parameter preserve_keys is set to TRUE, key ING is maintained. Otherwise, the values after placement will correspond
The corresponding key z at the previous position
?
$states = array("Delaware" , "Pennsylvania" , "New Jersey");print_r(array_reverse($states));// Array ( [0] => New Jersey [1] => Pennsylvania [2] => Delaware )
?
You can compare it with the result obtained when preserve_keys is enabled.
?
$states = array("Delaware" , "Pennsylvania" , "New Jersey");print_r(array_reverse($states, 1));// Array ( [2] => New Jersey [1] => Pennsylvania [0] => Delaware )
?
The array using the correlated Key will not be affected by preserve_keys, and key ING will always be maintained for the associated array.
Replace the array key and value
The array_fl ip () function replaces the role of the input key and corresponding value in the array. The format is as follows: z
?
array array_flip(array array)
?
The following is an example of this function z
$state = array("Delaware" ,"Pennsylvania" , "New Jersey");$state = array_flip($state);print_r($state);
?
In this example, the following result is returned:
Array ( [Delaware] => 0 [Pennsylvania].=> 1 [New Jersey] => 2 )
?
?
For more information about the tutorial, see [PHP and mysql programming]. on page 6, OK bookstore (www.okyun.com) provides free e-books: Click to download.
?
?
?