How to var_dump an Array in Order (PHP)
To var_dump an array in order, you can use the ksort() function to sort the array by keys before dumping it with var_dump(). Here's an example:
$array = array(
'c' => 'value3',
'a' => 'value1',
'b' => 'value2'
);
ksort($array); // Sort the array by keys
var_dump($array); // Dump the sorted array
Output:
array(3) {
['a']=>
string(6) "value1"
['b']=>
string(6) "value2"
['c']=>
string(6) "value3"
}
In this example, the ksort() function is used to sort the array by keys in ascending order. The var_dump() function is then used to display the sorted array.
原文地址: https://www.cveoy.top/t/topic/qegT 著作权归作者所有。请勿转载和采集!