PHP inverse array and permutation array keys and values
Inverse array element order
The Array_reverse () function resets the order of the elements in the array. The form is as follows:
?
Array array_reverse (array array [, Boolean Preserve_keys])
?
If the optional parameter Preserve_keys is set to true, the key mapping is persisted. Otherwise, the re-placed values will correspond to the first
The corresponding key z in the previous position
?
$states = Array ("Delaware", "Pennsylvania", "New Jersey");p Rint_r (Array_reverse ($states));//Array ([0] = new Jerse y [1] = Pennsylvania [2] = Delaware)
?
Can be compared with the results obtained when Preserve_keys is enabled
?
$states = Array ("Delaware", "Pennsylvania", "New Jersey");p Rint_r (Array_reverse ($states, 1));//Array ([2] = new Je Rsey [1] = Pennsylvania [0] = Delaware)
?
Arrays that use associative keys are unaffected by Preserve_keys, and the key mappings are always maintained for associative arrays.
Permutation array keys and values
The ARRAY_FL IP () function displaces the role of the keys and their corresponding values in the array. The form is as follows Z
?
Array array_flip (array array)
?
Here is an example of this function Z
$state = Array ("Delaware", "Pennsylvania", "New Jersey"), $state = Array_flip ($state);p rint_r ($state);
?
This example returns the following result Z
Array ([Delaware] = 0 [pennsylvania].=> 1 [New Jersey] + 2)
?
?
"To the fishing" detailed tutorial See "PHP and MySQL program design," The 52nd page, OK Bookstore (www.okpdf.com) to provide free ebook download address: Click to download
?
?
?