says I want to get a value of something and store in into an arr to produce json :
foreach($item as $items){
$items = $someting->name;
$arr = array(
\'
In most cases json_encode should be called once only. Keep adding all you want to convert to JSON in a php array, then call json_encode
$json = array('items' => array());
foreach ($items as $item) {
$json['items'][] = array(
'itemName' => $item->name
);
};
echo json_encode($json);
You could also call json_encode for all your $items array without doing a loop
json_encode($items)