PHP Append an array to a sub array

后端 未结 2 1545
攒了一身酷
攒了一身酷 2021-01-28 10:01

I need to make an array of locations arrays, it must look like this

$relevanceKeys = array(
    \'locations\' => array(

        array(
            \'longitud         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-28 10:45

    Just append the array like this:

    $relevanceKeys['locations'][] = $array;
                             //^^ See here
    

    You don't have to merge them all the time!

    Also I think you want to change this:

    $array = array(
                 array (
                     'longitude' => $row->longitude,
                     'latitude' => $row->latitude
                 )
           );
    

    to this to get your expected structure:

    $array = array(
                 'longitude' => $row->longitude,
                 'latitude' => $row->latitude
           );
    

    For more information about array see the manual: http://php.net/manual/en/language.types.array.php

提交回复
热议问题