排序多维数组PHP

时间:2015-07-25 00:04:05

标签: php cakephp

我在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")
)

我需要按" id"订购。我尝试过使用usort和许多多维解决方案,但对我来说并不适用。

我用过:

$price = array();
foreach ($inventory as $key => $row)
{
    $price[$key] = $row['price'];
}
array_multisort($price, SORT_DESC, $inventory);

但是没有用,因为我的阵列有许多维度。

$departamento = $this->Departamentos->get($id, [
        'contain' => [
            'Asignaturas.Mallas',
            'Asignaturas.Secciones.Perfiles',
            'Asignaturas.Secciones.Mallas.Carreras',
            'Unidades'
        ]
    ]);

这是我在Cakephp中的查询。我需要通过Secciones.id订购

1 个答案:

答案 0 :(得分:0)

我使用了Hash :: sort wrapper methods

对我来说效果很好;)

相关问题