回应一个foreach循环

时间:2016-06-23 19:18:33

标签: php arrays multidimensional-array foreach echo

我有array

 [result] => Array
        (
    [professions] => Array
                (
                    [primary] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 755
                                    [recipes] => Array
                                        (
                                            [0] => 25255
                                            [1] => 25278
                                            [2] => 25280

我需要回显[recipes]数组中的所有数字,25255, 25278...

这是我的开始:

<ul class="list">';

        foreach ($r['result']['professions']['primary']['0']['recipes'] as $item) echo '

<li>
', $item['???'], '.

</li>';


echo '
                </ul>
</ul>';

2 个答案:

答案 0 :(得分:0)

您的想法是正确的,只有一些语法问题。看起来应该更像这样:

textBox4.Invoke(new MethodInvoker(delegate
{
    if (ListViewCostumControl.lvnf.Items[i].Text.ToLower().Contains(textBox4.Text.ToLower()))
    {
        ListViewCostumControl.lvnf.Items[i].ForeColor = color;
    }
    backgroundWorker2.ReportProgress(i * 100 / ListViewCostumControl.lvnf.Items.Count);
})

答案 1 :(得分:0)

你说得对。修改因为语法不正确: -

<ul class="list"> <!-- remove extra '; -->

 <?php foreach ($r['result']['professions']['primary']['0']['recipes'] as $item){
     echo '<li>'.$item.'</li>'; // instead of $item['?'] just use $item and check the concatenation
 ?>
</ul> <!-- only this much is sufficient -->