PHP - sort multidimensional array by key

前端 未结 1 1726
死守一世寂寞
死守一世寂寞 2021-01-25 04:40

I got a multidimensional array which may look like this:

$array[1][0] = \"string\";
$array[0][1] = \"anotherstring\";
$array[0][0] = \"thirdstring\";
$array[1][1         


        
相关标签:
1条回答
  • 2021-01-25 05:02

    You can shorten your loop with:

    ksort($array);
    foreach($array as &$value) {
            ksort($value);
    }
    

    Or use array_walk:

    ksort($array);
    array_walk($array, 'ksort');
    
    0 讨论(0)
提交回复
热议问题