Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
Can't draw a conclusion from a JSON query in php? - bug-code.com Q&A

Can't draw a conclusion from a JSON query in php?

0 like 0 dislike
14 views
In General, everything is simple but at the same time are unable to conclude the piece of json result
5b5ca7533758e417916162.jpeg

Connected respectively to json
In order to make in php using foreach

<?php foreach($data as $a): ?>\r<?= $a->number ?> <?php endforeach; ?>


But I can't print the line number
Help can someone tell me how, maybe I something wrong doing? Thanks in advance!
asked by | 14 views

2 Answers

0 like 0 dislike
<? var_dump($data->number); ?>The way it works.
So and so, too, until the first object:
<?php foreach($data as $a): ?>\r<?= $a ?>\r<?php endforeach; ?>

So in this version (all objects do json-AMI):
<?php foreach($data as $k=>$a): ?> <?=(is_string($a))?"$k=>$a
":"$k=>".json_encode($a)."
"?> <?php endforeach; ?>

Since json is a structure, and to extract a custom field you need to write a recursive function that will iterate through all the tree and find the desired value. Or explicitly specify the desired through a series of "->" setting the path correctly on the "tree" to the desired node.
answered by
0 like 0 dislike
so you iterate nothing - you have only one object, not an array of objects.
toric on one simple object iterates over its properties and the$a->number will patalu (because $a is not an object).

in your case you need the entire code to replace in just <?= $data->number ?>
for clarity - https://ideone.com/VM6kdT
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

13.3k users

24,788 questions
46,220 answers
0 comments
13,321 users