如何在PHP中访问多维数组?

如何在PHP中访问多维数组?,php,arrays,Php,Arrays,您好,我正在使用mysqli_fetch_assoc()从数据库中获取数据,并得到这个结果 Array ( [poi_id] => 1 [created_id] => 1 [tour_id] => 1 [poi_title] => Kankariya Lake [poi_description] => Kankariya lake is a kankariya lake. [poi_category] => Hi

您好,我正在使用mysqli_fetch_assoc()从数据库中获取数据,并得到这个结果

Array
(
    [poi_id] => 1
    [created_id] => 1
    [tour_id] => 1
    [poi_title] => Kankariya Lake
    [poi_description] => Kankariya lake is a kankariya lake.
    [poi_category] => Historical
    [poi_base_price] => 10
    [poi_type] => driving
    [poi_address] => Kankaariya lake near maninagar
    [poi_city] => Ahmedabad
    [poi_state] => Gujaray
    [poi_country] => India
    [poi_latitude] => 23.006353
    [poi_longitude] => 72.601181
    [created_by] => Admin
    [status] => 1
    [time] => 2019-03-06 15:14:25
    [distance] => 7.981589182296636
)
Array
(
    [poi_id] => 2
    [created_id] => 1
    [tour_id] => 2
    [poi_title] => Kankariya Lake
    [poi_description] => Kankariya lake is a kankariya lake.
    [poi_category] => Historical
    [poi_base_price] => 10
    [poi_type] => driving
    [poi_address] => Kankaariya lake near maninagar
    [poi_city] => Ahmedabad
    [poi_state] => Gujaray
    [poi_country] => India
    [poi_latitude] => 23.006353
    [poi_longitude] => 72.601181
    [created_by] => Admin
    [status] => 1
    [time] => 2019-03-07 16:51:11
    [distance] => 7.981589182296636
)
Array
(
    [poi_id] => 3
    [created_id] => 1
    [tour_id] => 2
    [poi_title] => Kankariya Lake
    [poi_description] => Kankariya lake is a kankariya lake.
    [poi_category] => Historical
    [poi_base_price] => 10
    [poi_type] => driving
    [poi_address] => Kankaariya lake near maninagar
    [poi_city] => Ahmedabad
    [poi_state] => Gujaray
    [poi_country] => India
    [poi_latitude] => 23.006353
    [poi_longitude] => 72.601181
    [created_by] => Admin
    [status] => 1
    [time] => 2019-03-07 17:06:44
    [distance] => 7.981589182296636
)
现在我想访问for循环中的pertical数组元素,那么如何访问这些元素呢 我想将纬度和经度与阵列的所有其他纬度进行比较 我的更新代码

while ($poi_array = mysqli_fetch_assoc($qry_res)) 
{
    $poi_id=$poi_array['poi_id'];
    $new[]=$poi_array;
    //print_r($new);
    $lat1=$poi_array['poi_latitude'];
    $lon1=$poi_array['poi_longitude'];  
    //echo $new['poi_longitude'][1];

    $theta = $lon1 - $lon2;
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
    $dist = acos($dist);
    $dist = rad2deg($dist);
    $miles = $dist * 60 * 1.1515;
    $km= $miles * 1.609344;
    $meter=$km*1000;
    //echo round($meter);
    if($meter>1000)
    {                   
        $response2['success'] = true;
        $response2['message'] = "Pointof Interest list successfully fetched";
    }
    $fetch_media="SELECT * FROM poito_poi_media WHERE poi_id='".$poi_id."'";
    $media_qry_res = mysqli_query($con,$fetch_media);
    if (mysqli_num_rows($media_qry_res) > 0) 
    {
        while ($media_array = mysqli_fetch_assoc($media_qry_res)) 
        {
            $response4['media_id'] = $media_array['media_id'];
            $response4['image'] = $media_array['poi_image'];
            $response4['video'] = $media_array['poi_video'];
            $response4['ar'] = $media_array['poi_ar'];
            $response5[]=$response4;
            $response6['media_array']=$response5;
        }
    }
    else
    {
        $response6['media_array']=null;
    }
    $response['poi_id'] = $poi_array['poi_id'];
    $response['poi_title'] = $poi_array['poi_title'];
    $response['poi_description'] = $poi_array['poi_description'];
    $response['poi_category'] = $poi_array['poi_category'];
    $response['poi_base_price'] = $poi_array['poi_base_price'];
    $response['poi_type'] = $poi_array['poi_type'];
    $response['poi_address'] = $poi_array['poi_address'];
    $response['poi_city'] = $poi_array['poi_city'];
    $response['poi_state'] = $poi_array['poi_state'];
    $response['poi_country'] = $poi_array['poi_country'];
    $response['poi_latitude'] = $poi_array['poi_latitude'];
    $response['poi_longitude'] = $poi_array['poi_longitude'];
    unset($response5);
    $response['media_array'] = $response6['media_array'];

    $response3[]=$response;
    $response2['data']=$response3;
}
如果阵列中其他元素的距离在1000米以内,则仅给出一个元素的响应,无需在阵列中添加其他数据

意味着这也是placeinfo删除同一个位置如果一个位置多次出现,那么我们只能显示一个位置

while ($row = mysql_fetch_assoc($result)) {
    $rows[] = $row;
}

var_dump($rows);
//You can remove this
//it's just so that you can see the contents of the $row array
然后,您将能够遍历
$rows
数组,以找到所需的任何值。您可以将
$rows
放入
foreach()
循环中,如下所示:

foreach($rows as $row){
    //$row['poi_latitude']
    //$row['poi_longitude']
}

使用
foreach
loop如果已经有了一个循环,只需从该循环中的循环中获取元素。如何准确地获得给定的结果?你能分享现有的代码并标记你被卡住的地方吗?它是多维的,所以我如何在循环中访问poi_纬度和poi_经度@AnkurtiWari在您从
mysqli\u fetch\u assoc
获得的结果上放置一个循环,您可以直接访问该值。这对访问数组中的两个字段有何帮助?我已经扩展了答案,以进一步帮助OP。