我有一个SOAP结果集,所述的NuSOAP扩展已变成一个很好的阵列,用于我。我敢肯定,我会划伤了它的循环,因为我想要的东西的一些很长的路要走 - 但它似乎必须有一个更快的办法只有通过特定的数据元素循环。这里是数组:

Array
(
    [xxxResult] => Array
    (
        [NewDataSet] => Array
        (
            [Table] => Array
            (
                [0] => Array
                (
                    [ID] => 472
                    [Name] => abc
                    [Weight] => 0.15
                    [AppID] => 5133356895445
                )

                [1] => Array
                (
                    [ID] => 7396
                    [Name] => def
                    [Weight] => 0.11
                    [AppID] => 51348575554
                )

            )

        )

    )

)

因此,我想要做的只是通过这个这样,我得到的循环:

<tr>
    <td>[ID]</td>
    <td>[Name]</td>
    <td>[Weight]</td>
    <td>[AppID]</td>
</tr>

...每个表行。

似乎应该有比[xxxResult]一个更快的方式[NewDataSet] [表] [0] [ID]等

有帮助吗?

解决方案

像这样?

<?php

$tables = $soapResult['xxxResult']['NewDataSet']['Table'];

foreach ($tables as $table) {

?>
    <tr>
        <td><?php echo $table['ID']; ?></td>
        <td><?php echo $table['Name']; ?></td>
        <td><?php echo $table['Weight']; ?></td>
        <td><?php echo $table['AppID']; ?></td>
    </tr>
<?php

}

其他提示

像:

 for ($row = 0; $row < 2; $row++){
echo "<tr>";

for ($col = 0; $col < 4; $col++)
{
    echo "<td>".$myarray[$row][$col]."</td>";
}

echo "</tr>";

}

当然,如果行或COLS的量改变你需要获得阵列的长度。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top