0

what I'm trying to do is display some values I get into an array, here is how my array comes:

{"latitude":53.4749648,"longitude":-2.2083765,"addresses":["219 Ashton Old Road, , , , , Manchester, Greater Manchester","221 Ashton Old Road, , , , , Manchester, Greater Manchester","Beswick Convenience Store, 217 Ashton Old Road, , , , Manchester, Greater Manchester","Treads, 223 Ashton Old Road, , , , Manchester, Greater Manchester","Wong Wong Bakery, 163 Ashton Old Road, , , , Manchester, Greater Manchester"]}

now what I'm trying to display are the values from the "addresses", I'm trying to do a "while", for all the values, and print each of them, each address basicaly, hope I've explained myself well.

1
  • You want print_r ? Commented Nov 28, 2017 at 2:44

2 Answers 2

1

Are you looking like this?

$json = '{"latitude":53.4749648,"longitude":-2.2083765,"addresses":["219 Ashton Old Road, , , , , Manchester, Greater Manchester","221 Ashton Old Road, , , , , Manchester, Greater Manchester","Beswick Convenience Store, 217 Ashton Old Road, , , , Manchester, Greater Manchester","Treads, 223 Ashton Old Road, , , , Manchester, Greater Manchester","Wong Wong Bakery, 163 Ashton Old Road, , , , Manchester, Greater Manchester"]}';
$arr = json_decode ($json, true); 
echo "<pre>";print_r($arr); echo "</pre>";

foreach ($arr['addresses'] as $key=>$val) {
    echo "<br />".$key. ' => '.$val;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Assume your variable data contains all the json, can't you just write like

foreach($data as $val){ 
   echo $val["address"];
}

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.