dongliao2241 2014-01-01 13:45
浏览 25
已采纳

3×警告:Foreach [关闭]

I've a bit trouble with "foreach". The test page displays:

*Warning: Invalid argument supplied for foreach() in /data/web/virtuals/23481/virtual/www/subdom/vsohbrno/poi/junaio/junaio/test.php on line 60*

*Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in /data/web/virtuals/23481/virtual/www/subdom/vsohbrno/poi/junaio/junaio/test.php on line 64*

*Warning: Invalid argument supplied for foreach() in /data/web/virtuals/23481/virtual/www/subdom/vsohbrno/poi/junaio/junaio/test.php on line 68*

However I make it for Junaio (AR application for smartphone) - and when I tried to run it here (in the app), I had no trouble with it - it's working. But if the warnings will be disappear also in www pages, it would be fine =o)

My source code:

<?php

require_once '../ARELLibrary/arel_xmlhelper.class.php';

if(!empty($_GET['l']))
    $position = explode(",", $_GET['l']);
else
    trigger_error("user position (l) missing. For testing, please provide a 'l' GET parameter with your request. e.g. pois/search/?l=23.34534,11.56734,0");

//create the xml start
ArelXMLHelper::start(NULL, "/arel/index.html");

//start by defining some positions of geo referenced POIs and give those names and thumbnails
$treasureLocations = array(  
    array("48.6045911000,14.7007322000,0", "Tradiční výroba marmelád a povidel ", "Jih Čech > Šumava > Šumava a Pošumaví. Obec: Pohorská Ves."),  
    array("48.6438239000,14.2208661000,0", "Restaurace Czech Specials (Restaurace Lanovka)", "Jih Čech > Šumava > Šumava a Pošumaví. Obec: Lipno nad Vltavou."),  
    array("48.6541914000,14.0354000000,0", "Plavení dřeva, vorařství – Schwarzenberský plavební kanál", "Jih Čech > Šumava > Šumava a Pošumaví. Obec: Přední Výtoň."),  
);

//in the filter_value, the continent parameter will be send from the client, once the continent is filtered
$filter = $_GET['filter_value'];

//display the POIs as defined in the Constructor
$countpoi = 1;
foreach($treasureLocations as $i => $findPOI)
{    
  //Parameters for distance calculate. $Location = GPS coordinates of the POI, $Position = my GPS position. 
  $location = explode(",", $findPOI[0]);

  //Calculate distance beween my position and POI
  $deg2RadNumber = (float)(pi() / 180); 
  $earthRadius= 6371.009; 
  $latitudeDistance=((float)$position[0]-(float)$location[0])*$deg2RadNumber; 
  $longitudeDistance=((float)$position[1]-(float)$location[1])*$deg2RadNumber; 
  $a=pow(sin($latitudeDistance/2.0),2) +  cos((float)$position[0]*$deg2RadNumber) * cos((float)$location[0]*$deg2RadNumber) * pow(sin($longitudeDistance/2.0),2); 
  $c=2.0*atan2(sqrt($a),sqrt(1.0- $a)); 
  $distance=round($earthRadius*$c); 


  //Set distance for displaying objects (in kilometers)
  if($distance < 10)
  {    
    $title = $findPOI[1];   //Title of the POI
    $poi[$countpoi]['attribution'] = $findPOI[2]; //Description of the POI  
    $poi[$countpoi]['distance'] = $distance; // Distance between POI and me 

    //create the POI
    $poi[$countpoi]['poi'] = ArelXMLHelper::createLocationBasedPOI($i, $title, explode(",", $findPOI[0]), "http://vsohbrno.chudst.cz/poi/poi_obrazek.png", "http://vsohbrno.chudst.cz/poi/poi_obrazek.png", $poi[$countpoi]['attribution'], NULL);    
    $countpoi++;
   }
}       

  //Sorting POI (the closest -> the furthest)      
  foreach ($poi as $val)
  {
    $sortarray[] = $val['distance'];
  }
  array_multisort($sortarray,$poi);


  //Write 39 POI to XML file
  foreach ($poi as $POInumber => $POIvalue)
  {
    if($POInumber < 39){
     if(!empty($filter))
     {
        if(strtolower($filter) == strtolower($poi[$POInumber]['attribution']))
        {
            ArelXMLHelper::outputObject($poi[$POInumber]['poi']); 
        }       
    } 
     else
         {ArelXMLHelper::outputObject($poi[$POInumber]['poi']);}
    }     
  } 



//end the output
ArelXMLHelper::end();

?>
  • 写回答

1条回答 默认 最新

  • dongshanni1611 2014-01-01 14:00
    关注

    If the distance is never smaller than 10 km, $poi will not be initialised, which is what the error means.

    Initialise $poi to be an array and it should remove the warnings:

    $poi = array();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题