0
 $values = (object)$arr;
 var_dump($values);

var_dump 产生这些:

object(stdClass)[1]
  public 'time' => float 0.002
  public 'distance' => float 0.156
  public 'code' => string '1' (length=1)
  public 'result' => 
    array (size=17)
      0 => string '2.94053, 101.787, A' (length=24)
      1 => string '2.94043, 101.787, A' (length=24)
      2 => string '2.9404, 101.787, A' (length=23)
      3 => string '2.94029, 101.787, A' (length=24)
      4 => string '2.94025, 101.787, A' (length=24)
      5 => string '2.9402, 101.787, A' (length=23)
      6 => string '2.94016, 101.787, A' (length=24)
      7 => string '2.94007, 101.787, A' (length=24)
  public 'arrayPosition' => 
    array (size=1)
      0 => 
        array (size=1720)
          0 => string '2.93955, 101.788, B' (length=22)
          1 => string '2.93951, 101.788, B' (length=22)
          2 => string '2.93926, 101.788, B' (length=22)
          3 => string '2.93921, 101.788, B' (length=22)
          4 => string '2.9392, 101.788, B' (length=21)
          5 => string '2.93911, 101.788, B' (length=22)
          6 => string '2.93906, 101.789, B' (length=22)
          7 => string '2.93896, 101.789, B' (length=22)

如何读取result和的每个值arrayPosition?通过使用这个

           echo "<br>".$values->time."<br>";
           echo $values->distance."<br>";
           echo $values->code."<br>";
           echo $values->result."<br>";
           echo $values->arrayPosition."<br>";

将失败result并且arrayPosition

Notice: Array to string conversion
4

3 回答 3

1

arrayPosition如果您知道想要的元素的子索引,则可以通过多种方式访问​​它

 $values->arrayPosition[0][index_number]; //you may require the first dimension index if you have more than one element there as well

另一种方法是使用循环

 foreach ($values->arrayPosition as $levelone) {
      foreach ($levelone as $key => $leveltwo) {
            echo $leveltwo;
      }
 }
于 2013-06-23T10:09:19.417 回答
1
foreach($values as $value)
{
  foreach($value->result as $result1)
  {
    echo($result1);
    echo("<br>");
  }
  foreach($value->arrayPosition as $arrayposition2)
  {
    foreach($arrayposition2 as $arrayposition_child)
    {
      echo($arrayposition_child);
      echo("<br>");
    }
  }
}
于 2013-06-23T10:16:28.760 回答
1

要访问这两个变量,您可以:

1)
foreach( $values->result as $row ) {
     echo $row;
}

2)
foreach( $values->arrayPosition as $mulRow ) {
     foreach( $mulRow as $row ) {
         echo $row;
     }
}
于 2013-06-23T10:17:25.983 回答