Ming han
Ming han

Reputation: 17

Convert 2 arrays into one 2 dimensional array php

I developed code for get mysql table data.

$latvalue = Array();
    $logvalue = Array();

    while ($row = mysqli_fetch_array($resultstore, MYSQL_ASSOC)) {
    $latvalue[] = $row['lat']; 
    $logvalue[] = $row['log']; 
}  

So its like (45 ,56,34) (10 ,20,30) for example

I want to combine those 2 arrays into one 2 dimensional array.

Example

 $data = array
 (
   0 => array(45, 10),
  1 => array(56, 20),
  2 => array(34, 30),
  );  

I can't figure out logic to do this. Please help.

Upvotes: 0

Views: 55

Answers (1)

E_p
E_p

Reputation: 3144

You can change your code to do it:

$latlong = array();

while ($row = mysqli_fetch_array($resultstore, MYSQL_ASSOC)) {
    $latlong[] = array($row['lat'], $row['log']);
} 

Upvotes: 2

Related Questions