PHP Append an array to a sub array

后端 未结 2 1579
攒了一身酷
攒了一身酷 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:32

    Since you're only needing to push elements to the array, you can simply use the [] struct as follows:

    while ($row = $result->fetch_object()) 
    {
        $relevanceKeys['locations'][] = array (
            'longitude' => $row->longitude,
            'latitude' => $row->latitude
        );
    } 
    

提交回复
热议问题