简体   繁体   English

通过PHP数组

[英]Going through PHP array

I have a php array I would like get a specific data from it. 我有一个php数组,我想从中获取特定数据。

 [vxs_data] => Array
    (
        [0] => Array
            (
                [data] => Array
                    (
                        [0] => fsafas
                        [1] => 603
                        [2] => 39
                        [3] => 81
                        [4] => 12
                        [5] => 43
                        [6] => 186
                        [7] => 97
                        [8] => 129
                    )

            )

        [1] => Array
            (
                [data] => Array
                    (
                        [9] => fsdfsa
                        [10] => 60
                        [11] => 30
                        [12] => 184
                        [13] => 12
                        [14] => 7
                        [15] => 176
                        [16] => 132
                        [17] => 119
                    )

            )

        [2] => Array
            (
                [data] => Array
                    (
                        [18] => fsafsa
                        [19] => 60
                        [20] => 3121
                        [21] => 18
                        [22] => 11
                        [23] => 0
                        [24] => 199
                        [25] => 140
                        [26] => 117
                    )

            )

        [3] => Array
            (
                [data] => Array
                    (
                        [27] => dada
                        [28] => 60
                        [29] => 27
                        [30] => 11
                        [31] => 22
                        [32] => 1
                        [33] => 22
                        [34] => 157
                        [35] => 98
                    )

            )

        [4] => Array
            (
                [data] => Array
                    (
                        [36] => ASKLMSDAS
                        [37] => 60
                        [38] => 232
                        [39] => 11
                        [40] => 23
                        [41] => 4
                        [42] => 32
                        [43] => 141
                        [44] => 98
                    )

            )

The content of array about that. 关于数组的内容。 I would like to get that data in to table (td) so it would be like this: 我想将这些数据放入表(td)中,因此如下所示:

<tr>
    <td><a href="#">ASKLMSDAS</a></td><td>33</td>...
</tr>
<tr>
    <td><a href="#">dada</a></td><td>33</td>...
</tr>

So I would like a make link of those first data columns like "ASKLMSDAS" "dada". 因此,我想建立诸如“ ASKLMSDAS”,“ dada”之类的第一批数据列的链接。 So I need to do some sort of if clause maybe and foreach? 所以我需要做一些if子句,也许和foreach吗?

Thanks so much and sorry about my english. 非常感谢,对我的英语感到抱歉。

Not exactly sure what you're going for, but heres a pretty generally way of making a table from the contents of 2d array. 不确定要做什么,但是这是一种从2d数组的内容制作表格的一般方法。 Hopefully you can tweak it to do what you want. 希望您可以对其进行调整以执行所需的操作。

echo "<table>";
foreach($smliiga_data as $row_k => $row_v)
{
     echo "<tr><td><strong>$row_k</strong></td>";
     foreach($row_v['data'] as $k=>$v)
     {
         $str = is_int($v) ? "$k: $v" : "<a href='#'>$k: $v</a>"; //this makes link for the ones that are not numbers
         echo "<td>$str</td>";
     }
     echo "</tr>";
}
echo "</table>";
$array = array_reverse($array);

foreach($array as $childArray)
{
   echo '<tr><td><a href="#">';
   echo current($childArray['data']);  // write other html as you want, this will give you the element what you want
   echo '</a></td><td>33</td>...</tr>';
}

This should work: 这应该工作:

foreach ($mliiga_data as $row){
    $linktext =  $row[data][0];
    //
    // Dispaly linktext
    //
}

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

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