开发者

CakePHP deep sorting

I would like sortking by name in assosciate model using Set::sort(). My code look like:

$arr = array(
            0 => array(
                'Category' => array(
                    'name' => 'aaa'),
                'Section' => array(
                    0 => array(
                        'name' => '开发者_运维问答b'),
                    1 => array(
                        'name' => 'a'),
                    2 => array(
                        'name' => 'c'))));

        $brr = Set::sort($arr, '{n}.Section.name', 'ASC');
        pr($brr);


You were pretty much almost there, you forgot the numeric index for the Section array.

$arr = array(
    0 => array(
        'Category' => array(
            'name' => 'aaa'),
        'Section' => array(
            0 => array(
                'name' => 'b'),
            1 => array(
                'name' => 'a'),
            2 => array(
                'name' => 'c')
        )
    )
);

$brr = Set::sort($arr, '{n}.Section.{n}.name', 'ASC');
pr($brr);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜