Answer the question
In order to leave comments, you need to log in
How to display the entire value of the array and not just one?
I have a primary array
{
"results": [
{
"question": "Ты кто?",
"answer": "Вася",
"topic": [
"Имя"
]
},
{
"question": "Сколько лет?",
"answer": "5",
"topic": [
"Возраст"
]
}
}
$qan1 = []; $qan2 = []; $qan3 = []; $qan5 = '';
foreach ($data['results'] as $repository2){ foreach ($repository2['topic'] as $repository3){
$qan3[] = $repository3;}
$qan1[] = $repository2['question'];
$qan2[] = $repository2['answer'];}
$qan4 = array($qan3,$qan1,$qan2);
foreach ($qan4 as $repos):
$qan5 .= '<dt><span>'.$repos[0].'</span><div class="acc-icon-wrap parallax-wrap"><div class="acc-button-icon parallax-element"><i class="fa fa-angle-down"></i></div></div></dt><dd class="accordion-content"><h3>Question</h3><dd>'.$repos[1].'</dd><h3>Answer</h3><dd>'.$repos[2].'</dd></div>';
endforeach;
return $qan5;
(
[0] => Array
(
[0] => Имя
[1] => Возраст
)
[1] => Array
(
[0] => Ты кто?
[1] => Сколько лет?
)
[2] => Array
(
[0] => Вася
[1] => 5
)
)
foreach ($qan4 as $repos):
$qan5 .= '<dt><span>'.$repos[0].'</span><div class="acc-icon-wrap parallax-wrap"><div class="acc-button-icon parallax-element"><i class="fa fa-angle-down"></i></div></div></dt><dd class="accordion-content"><h3>Question</h3><dd>'.$repos[1].'</dd><h3>Answer</h3><dd>'.$repos[2].'</dd></div>';
endforeach;
return $qan5;
($qan4[0] as $reposit) : echo $reposit; endforeach;
Answer the question
In order to leave comments, you need to log in
So, first of all, you don't need to output via echo html.
Secondly, you have all the necessary keys in the cycle, you seem to be dumb, so I explain it on my fingers, I hope it helps ...
<?php
...
foreach ($data['results'] as $repo){
?> //закрыли пхп, дальше выводим хтмл
<dt>
<span>
<?=join(', ', $repo['topic']);?> //сделали пхп вывод где надо, и дальше выводим хтмл...
</span>
<div class="acc-icon-wrap parallax-wrap">
<div class="acc-button-icon parallax-element">
<i class="fa fa-angle-down"></i>
</div>
</div>
</dt>
<dd class="accordion-content">
<h3>Question</h3>
<dd><?=$repo['question']?></dd>
<h3>Answer</h3>
<dd><?=$repo['ansver']?></dd>
<?php } ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question