Going through PHP array
I have a php array I would like get a specific data from it.
[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:
<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". So I need to do some sort of if clause maybe and 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. 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>";
This should work:
foreach ($mliiga_data as $row){
$linktext = $row[data][0];
//
// Dispaly linktext
//
}
$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>';
}
精彩评论