Ok so I am trying to make a loop in php for json but I dont know what or how to loop it where I can keep the format I want for the JSON output. This is what i have:
$number = array(31,25,160);
$json_holder = array();
$counter = count($names);
$i = 0;
while($i < $counter){
$json_holder = array('user'=> array('results'=> array('tagnumber' => $number[$i],'status'=>'good'),);
echo json_encode($json_holder);
$i++;
}
And my output:
{"user":{"results":{"tagnumber":31,"status":"good"}}}
{"user":{"results":{"tagnumber":25,"status":"good"}}}
{"user":{"results":{"tagnumber":160,"status":"good"}}}
So instead of making new JSON root elements everytime I want to just make a new array in results so it would output like:
{
"user": {
"results": [{
"tagnumber": 31,
} {
"tagnumber": 25,
} {
"tagnumber": 160,
}],
"status": "okay"
}
}
I hope I am making sense
whileloop not infinite loop without an$i++?