I have an example array get form database column like this :
[0] => {"data_1":"content_1","data_2":"content_2"}
[1] => {"data_1":"content_1","data_2":"content_2"}
How do i decode this json and loop it in foreach php ? Thank you in advance.
I have an example array get form database column like this :
[0] => {"data_1":"content_1","data_2":"content_2"}
[1] => {"data_1":"content_1","data_2":"content_2"}
How do i decode this json and loop it in foreach php ? Thank you in advance.
Try below code
$array=array('{"data_1":"content_1","data_2":"content_2"}','{"data_1":"content_1","data_2":"content_2"}');
foreach($array as $a)
{
$data=json_decode( $a );
//print_r($data);
foreach($data as $k=>$d)
{
echo $k.':'.$d;
echo "<br>";
}
}
Output
data_1:content_1
data_2:content_2
data_1:content_1
data_2:content_2
You may to have to start like this:
$JSONGetter = json_decode($GETjson, true);
foreach ($JSONGetter as $value){
$DataContent = $value['data_1'];
var_dump(array_map(function ($value) {
return json_decode($value, true);
}, [
0 => '{"data_1":"content_1","data_2":"content_2"}',
1 => '{"data_1":"content_1","data_2":"content_2"}'
]));
try this below code
<?php
$nomor = 1;
foreach ($data_array as $data) :
$data_student_array = json_decode($data->DATA_STUDENT, true); ?>
<?php
$nomor1 = 1;
foreach($data_student_array as $data_student_value)
{
?>
<tr>
<td><?php echo $nomor1; ?></td> <td><?php echo $data_student_value['data_1']; ?></td>
<td><?php echo $data_student_value['data_2']; ?></td>
</tr>
<?php
$nomor1++;
}
?>
<?php $nomor++;
endforeach;
?>