views:

216

answers:

2

I have a SOAP result set that the nuSoap extension has turned into a nice array for me. I'm sure I could scratch out some long way of looping it for what I want - but it seems there must be a faster way to just loop through the specific data elements. Here is the array:

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
                )

            )

        )

    )

)

So what I want to do is simply loop through this such that I get:

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

...for each table row.

Seems there should be a quicker way than [xxxResult][NewDataSet][Table][0][ID] etc.

+4  A: 

Like this?

<?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

}
Ionuț G. Stan
I think he wants a more general solution, where the first two arrays might possibly have more than one element. In that case, wouldn't it be smarter to use three foreach loops-- just in case?
Platinum Azure
of course! thanks. really need to make sure to get some sleep :)Platinum: If I did not know the resultset would be fairly static, you are right I would need a more dynamic solution. In this case the provider and client are different applications in the same company, so I can know when a change is coming.
menkes
A: 

Like:

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

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

echo "</tr>";

}

Of course if the amount of rows or cols changes you need to get the length of the arrays.

Jonas B