I am Trying to convert array to json but not getting exact result I am looking for.
Here,
<?php
$result=array();
$result[status]=1;
$data=array(
array("ucode" => "123","name" => "abc","lname" => "xyz"),
array("ucode" => "431","name" => "cdb","lname" => "zsa")
);
foreach($data as $res){
$data=array();
$data[ucode]=$res['ucode'];
$data[name]= $res['name'];
$data[lname]= $res['lname'];
$result[content]=$data;
}
echo $res=json_encode($result);
?>
Actul Result:
{"status":1,"content":{"ucode":"431","name":"cdb","lname":"zsa"}}
My expected Result:
{"status":1,"content":[{"ucode":"123","name":"abc","lname":"xyz"},{"ucode":"431","name":"cdb","lname":"zsa"}]}
please, Guide me where is mistake, not getting the expected result.
$result = ['status' => 1, 'content' => $data ];json_encode()round that and Bob's yer Uncle