简体   繁体   English

如何在数组中查询数组

[英]how to query array within an array

When I execute a print_r I get this result...当我执行print_r我得到了这个结果......

Array ( 
    [0] => Array (
        [A_program_id] => a0F36000008PIYF
        [XC_program_logo] => louisville.jpg
    )
    [1] => Array (
        [A_program_id] =>  a0F36000008qjSp
        [XC_program_logo] => alabama.jpg
    )
    [2] => Array (
        [A_program_id] => a0F36000008pRxL
        [XC_program_logo] => trinity.jpg
    )
)

How do I make a while loop or whatever to properly fetch needed to query something like this:我如何制作一个while循环或任何正确获取查询这样的东西所需的东西:

//zero based
echo"".$rows[0][0]."</td><td>"".$rows[1][0].""</td><td>"".$rows[2][0]."";
echo"".$rows[0][1]."</td><td>"".$rows[1][1].""</td><td>"".$rows[2][1]."";

to show显示

louisville.jpg      alabama.jpg       trinity.jpg
a0F36000008PIYF     a0F36000008qjSp   a0F36000008pRxL

please help thx请帮助thx

One possibility is to use array_column to extract each rows data from the source, and then implode to add the </td><td> between each value:一种可能性是使用array_column从源中提取每一行数据,然后内implode以在每个值之间添加</td><td>

echo implode('</td><td>', array_column($rows, 'XC_program_logo'));
echo implode('</td><td>', array_column($rows, 'A_program_id'));

Demo on 3v4l.org 3v4l.org 上的演示

This will give the same output as the two echo statements in your question.这将提供与您问题中的两个echo语句相同的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM