Hướng dẫn reverse array php
(PHP 4, PHP 5, PHP 7, PHP 8) Show array_reverse — Return an array with elements in reverse order Descriptionarray_reverse(array Parametersarray The input array. preserve_keys If set to Return ValuesReturns the reversed array. ExamplesExample #1 array_reverse() example
The above example will output: Array ( [0] => php [1] => 4 [2] => Array ( [0] => green [1] => red ) ) Array ( [0] => Array ( [0] => green [1] => red ) [1] => 4 [2] => php ) Array ( [2] => Array ( [0] => green [1] => red ) [1] => 4 [0] => php ) See Also
There are no user contributed notes for this page. Hàm Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức. Cú phápCú pháp: Trong đó:
Ví dụCode $array = array( "php", "js", "css", "html" ); $reversed = array_reverse($array); $preserved = array_reverse($array, true); echo ""; print_r($array); echo ""; echo ""; print_r($reversed); echo ""; echo ""; print_r($preserved); echo ""; Kết quả Array ( [0] => php [1] => js [2] => css [3] => html ) Array ( [0] => html [1] => css [2] => js [3] => php ) Array ( [3] => html [2] => css [1] => js [0] => php ) Tham khảo:php.net Bài viết này được đăng tại [free tuts .net] Hàm Cú phápCú pháp: Trong đó:
Ví dụCode $array = array( "php", "js", "css", "html" ); $reversed = array_reverse($array); $preserved = array_reverse($array, true); echo ""; print_r($array); echo ""; echo ""; print_r($reversed); echo ""; echo ""; print_r($preserved); echo ""; Kết quả Array ( [0] => php [1] => js [2] => css [3] => html ) Array ( [0] => html [1] => css [2] => js [3] => php ) Array ( [3] => html [2] => css [1] => js [0] => php ) Tham khảo:php.net
Hướng dẫn cách sử dụng hàm array_reverse() về mảng trong lập trình PHP Tác dụng của hàm array_reverse()The The following table summarizes the technical details of this function.
SyntaxThe basic syntax of the array_reverse(array, preserve); The following example shows the
ParametersThe
More ExamplesHere're some more examples showing how The following example shows how to reverse the order of array elements while preserving the keys.
Bài viết này đã giúp ích cho bạn?Bài viết mới |