This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP and JSON

PHP - Looping Through the Values

You can also loop through the values with a foreach() loop:

Peter => 35
Ben => 37
Joe => 43

<?php
// define a $jsonobj
$jsonobj = '{"Peter":35,"Ben":37,"Joe":43}';

// create $obj by running json_decode on $jsonobj
$obj = json_decode($jsonobj);

// run a foreach loop on each $obj $key => $value pair and display each result on a new line
foreach($obj as $key => $value) {
  echo $key . " => " . $value . "<br>";
}
?>