[英]Sorting Multi-Dimensional Array PHP
I've that proceed this array in PHP 我已经在PHP中进行了这个数组
array(
"id" => 1,
"name" => "Carlos"
"other" => array("key" => "Hello")
),
array(
"id" => 3,
"name" => "Carlos"
"other" => array("key" => "Hello")
),
array(
"id" => 2,
"name" => "Carlos"
"other" => array("key" => "Hello")
)
and I need to order by "id". 我需要按“ id”排序 I've try it using usort and many multidimensional solutions but doesn't work for me.
我已经尝试使用usort和许多多维解决方案,但对我不起作用。
I used that: 我使用了:
$price = array();
foreach ($inventory as $key => $row)
{
$price[$key] = $row['price'];
}
array_multisort($price, SORT_DESC, $inventory);
But doesn't work because my array has many dimentions. 但是不起作用,因为我的数组有很多尺寸。
$departamento = $this->Departamentos->get($id, [
'contain' => [
'Asignaturas.Mallas',
'Asignaturas.Secciones.Perfiles',
'Asignaturas.Secciones.Mallas.Carreras',
'Unidades'
]
]);
That is my query in Cakephp. 那是我在Cakephp中的查询。 I need to order by Secciones.id
我需要通过Secciones.id订购
I used Hash::sort http://book.cakephp.org/3.0/en/core-libraries/hash.html 我使用了Hash :: sort http://book.cakephp.org/3.0/en/core-libraries/hash.html
And works fine for me ;) 并且对我来说很好;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.