douzhenyu6533 2015-06-19 05:27
浏览 45

在数组php中创建动态数组

I have an sql query that returns the altitude of a place. I have exploded the result to separate longitude and latitude. The result is stored in array.

Now I want to create an array which should contain all the arrays returned by the explode function.

$sql_altitude = mysql_query("SELECT altitude FROM `navigatio_info`
                                             WHERE bus_id='$bus_id'
                                             AND driver_id ='$driver_id' 
                                             ORDER BY stop_no ASC 
                                             LIMIT 0 , 30");
while ($row = mysql_fetch_assoc($sql_altitude)) 
 {
   //echo $row['altitude'];
   //$altitude=array();
   $altitude=(explode("-",$row['altitude']));
   print_r($altitude);
   //$lat=array();
   $lat=$altitude[0];
   //print_r($lat);
   echo '<br/>';
   //$long=array();
   $long=$altitude[1];
   //print_r($long);
   //echo '<br/>';
}

below is a static array defined:

 <?php 
   $phpArray = array(array('Vadodara',22.3000,73.2000,5),
                     array('Valsad',20.6300,72.9300,2),
                     array('Thane',19.1724,72.9570,1));
 )?>

I want $phpArray to have dynamic values generated from the query above

  • 写回答

3条回答 默认 最新

  • douhe8981 2015-06-19 05:35
    关注
    $sql_altitude = mysql_query("SELECT altitude FROM `navigatio_info` WHERE bus_id='$bus_id'AND driver_id ='$driver_id' ORDER BY stop_no ASC LIMIT 0 , 30");
    $phparray = array();
    while ($row = mysql_fetch_assoc($sql_altitude)) 
    {
    $altitude=(explode("-",$row['altitude']));
    $lat=$altitude[0];
    $long=$altitude[1];
    $phparray = array($lat,$lat);
    }
    echo "<pre>";
    print_r($phparray)
    echo "<pre>";
    

    Please check above code:

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错