0

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.

0

2 Answers 2

4

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

}
Sign up to request clarification or add additional context in comments.

2 Comments

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

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.