PHP array replace numbers with keys

后端 未结 2 1687
眼角桃花
眼角桃花 2021-01-24 11:34

I have this array...

Array
(
    [result] => Success
    [finals] => Array
        (
            [0] => Array
                (
                    [id]         


        
相关标签:
2条回答
  • Saty answered it right. Here is the complete code:

    <?php
    $data = Array
        (
            'result' => 'Success',
            'finals' => Array
            (
                Array
                    (
                        'id' => 633,
                        'name' => 'RESULT84'
                    ),
                Array
                    (
                        'id' => 766,
                        'name' => 'RESULT2'
                    ),
                Array
                    (
                        'id' => 22,
                        'name' => 'RESULT1'
                    )
            )
        );
    
    $names = array_column($data['finals'], 'name','name');
    print_r($names);
    ?>
    
    0 讨论(0)
  • 2021-01-24 12:02

    Pass third parameter name into array_column to make it key

     $names = array_column($data['finals'], 'name','name');
     print_r($names);
    
    0 讨论(0)
提交回复
热议问题