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

var_dump produces these:

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)

How can I read each of the values of result and arrayPosition ? By using this

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

will fail on result and arrayPosition

Notice: Array to string conversion

3 Answers 3

1

to access arrayPosition there are couple of ways if you know the sub index of the element you want you can access it by

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

The other method is using a loop

 foreach ($values->arrayPosition as $levelone) {
      foreach ($levelone as $key => $leveltwo) {
            echo $leveltwo;
      }
 }
Sign up to request clarification or add additional context in comments.

Comments

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>");
    }
  }
}

Comments

1

for accessing those 2 variables, you can:

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

2)
foreach( $values->arrayPosition as $mulRow ) {
     foreach( $mulRow as $row ) {
         echo $row;
     }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.