多个数组中的单个数组值

时间:2018-05-24 13:21:27

标签: php

我在多个数组中尝试单个数组值。在回应之后 $users['ride_from']。我得到了这个结果32.9697, -96.80322。我的查询在这里可能我转换这个像持有两个数组的$ point1。任何帮助。

foreach ($usersInfo as $key=> $users){
    $ridefrom = $users['ride_from'];
    $rideto = $users['ride_to'];//this is from lat long
    $point1 = array("lat" => "48.8666667", "long" => "2.3333333"); // Paris (France)
}

2 个答案:

答案 0 :(得分:0)

试试这个

$finalDest = array();
foreach ($usersInfo as $key=> $users)
{
      $ridefrom=$users['ride_from'];
      $rideto=$users['ride_to'];//this is from lat long
      $tempLatLong = explode(',',$users['ride_to']);
      $key = array('lat','long');
      $to = array_combine($key,$tempLatLong); 
      array_push($finalDest,$to);  push destination of each user 
}

print_r($finalDest); // displays all array

答案 1 :(得分:0)

此代码:

$users['ride_to'] = "32.9697, -96.80322";
$users['ride_to'] = explode(",",$users['ride_to']);

$rideto["lat"] = $users['ride_to'][0];
$rideto["long"] = $users['ride_to'][1]; 


echo "<pre>";print_r($rideto);

返回: 排列 (     [lat] =&gt; 32.9697     [long] =&gt; -96.80322 )