I pull the data in json format, but I can’t access the sub-elements in some way, it’s not oddly worth it, it only takes the first character.
JavaScript
x
$log_example = $request->all();
$logs = json_encode($log_example);
$data = json_decode((string) $logs, true);
return $data['log_list'];
The returned data is as follows
JavaScript
{
"0":["1","SALES","5,00","REMOVED"],
"1":["2","SALES","10,00","REMOVED"],
"2":["1","BUYER","2","DROPPED"]
}
When I output with the dd function, the data returns as follows
dd($log_example);
return as below
JavaScript
array:1 [ "log_lists" => "{"0":["1"," SALES","10,00","REMOVED"],"1":["1"," SALES","10,00","REMOVED"],"2":["1"," BUYER","10,00","DROPPED"]}" ]
Here I want to pull the first data for example
JavaScript
foreach ($data as $d) {
echo $d[0];
}
return only this charecters {
Advertisement
Answer
The entry in the key value array is JSON
, not the whole log_example
, i would not decode it as you do, instead something like this.
JavaScript
$data = json_decode($log_example['log_lists'], true);
Now you should be able to loop as shown here.
JavaScript
foreach($data as $arr) {
foreach($arr as $value) {
var_dump($value)
}
}