I have a question. How to get content only from json data.
My JSON Data:
array(
(int) 0 => '{"html":"Lorem Ipsum \u2013 Lorem Ipsum \u2013 Lorem Ipsum - Lorem Ipsum \u2013 Lorem Ipsum \u2013 Lorem Ipsum \u2013 Lorem Ipsum"}',
(int) 1 => '{"text":"Lorem Ipsum"}',
(int) 2 => '{"text":"01 June-30 September"}',
(int) 3 => '{"text":"7 nights \/ 8 days"}',
(int) 4 => '{"text":"Lorem Ipsum"}'
);
I want to get html and text content only
Lorem Ipsum
Lorem Ipsum
01 June-30 September
I tried to use json_decode
.
My Code:
foreach($array as $i) {
$a = json_decode($i);
echo $a;
}
Anyone help me please?
Assume your data is stored in a variable called $a
.
echo json_decode($a[0], true)['html'];
will get you the result for the first index of the array. For the other indexes you would use text
instead of html
.
Note I've passed true
for the second argument of json_decode
, if you prefer to treat the decoded data as an object you can leave that argument off, in which case the code would become
echo json_decode($a[0])->html;