<?php
    $test = [
        'a' => [
        'mobile' => '13333333333',
        'other' => 'aaaaaaaaaaaa'
        ],
        'b' => [
        'mobile' => '14444444444',
        'other' => 'bbbbbbbbbb'
        ],
        'c' => [
        'mobile' => '14444444444',
        'other' => 'cccccccccc'
        ],
    ];
    
    $result = [];
    foreach ($test as $k => $v) {
        $result[$v['mobile']][] = $v;
    }
    
    echo "<pre>";
    print_r($test);
    echo "</pre>";
    
    echo "<pre>";
    print_r($result);
    echo "</pre>";
?>

返回结果:

Array
(
    [a] => Array
        (
            [mobile] => 13333333333
            [other] => aaaaaaaaaaaa
        )

    [b] => Array
        (
            [mobile] => 14444444444
            [other] => bbbbbbbbbb
        )

    [c] => Array
        (
            [mobile] => 14444444444
            [other] => cccccccccc
        )

)
Array
(
    [13333333333] => Array
        (
            [0] => Array
                (
                    [mobile] => 13333333333
                    [other] => aaaaaaaaaaaa
                )

        )

    [14444444444] => Array
        (
            [0] => Array
                (
                    [mobile] => 14444444444
                    [other] => bbbbbbbbbb
                )

            [1] => Array
                (
                    [mobile] => 14444444444
                    [other] => cccccccccc
                )

        )

)

 

发表评论

Close Menu