Multi-dimensional array sorting has an array: PHPcode & lt ;? Php $ arr = array (1, 0), array (2, 0), array (3, 0), array (4, 0), array (5, 1), array (6, 1 ), array (7, 5), array (8, 2 ));? & Gt; multi-dimensional array sorting
There is an array:
PHP code
The result to be sorted is:
PHP code
That is, $ arr [$ I] [0] ==$ arr [$ j] [1]. then $ arr [$ j] is placed behind $ arr [$ I ].
Actually, it is an order of infinite categories. I try to process multiple cycles, but it is a little troublesome. I want to implement it using recursion, only $ arr [$ I] [0] = 1 is implemented. please help
There are only a few categories.
------ Solution --------------------
Write in this way
PHP code
$arr = array(array(1,0),array(2,0),array(3,0),array(4,0),array(5,1),array(6,1),array(7,5),array(8,2));print_r(foo($arr));function foo($ar, $p=0) { $r = array(); foreach($ar as $v) { if($v[1] == $p) { $r[] = $v; $r = array_merge($r, foo($ar, $v[0])); } } return $r;}