按照seq字段升序排列
<?php //将下面的数据内外皆排序 $list = array( array( ‘seq‘ => 3, ‘data‘ => array( array( ‘seq‘ => 2, ‘desc‘ => ‘我的序号是内2‘ ), array( ‘seq‘ => 1, ‘desc‘ => ‘我的序号是内1‘ ), array( ‘seq‘ => 3, ‘desc‘ => ‘我的序号是内3‘ ), ) ), array( ‘seq‘ => 1, ‘data‘ => array( array( ‘seq‘ => 2, ‘desc‘ => ‘我的序号是内2‘ ), array( ‘seq‘ => 1, ‘desc‘ => ‘我的序号是内1‘ ), array( ‘seq‘ => 3, ‘desc‘ => ‘我的序号是内3‘ ), ) ), array( ‘seq‘ => 2, ‘data‘ => array( array( ‘seq‘ => 2, ‘desc‘ => ‘我的序号是内2‘ ), array( ‘seq‘ => 1, ‘desc‘ => ‘我的序号是内1‘ ), array( ‘seq‘ => 3, ‘desc‘ => ‘我的序号是内3‘ ), ) ) ); function mySort($x, $y) { return $x[‘seq‘] - $y[‘seq‘]; } foreach ($list as $key => $value) { usort($list[$key][‘data‘] ,‘mySort‘);//注意只能不能将 $list[$key][‘data‘] 替换为 $value[‘data‘] } usort($list, ‘mySort‘); echo json_encode($list); ?>
时间: 2024-10-11 10:50:43