I am looking for a solution to handle an exception. In API I have, details about Orders are saved in arrays of objects: This in an example when there are at least two items:
Array
(
[0] => stdClass Object
(
[Cena] => 60,66
[CenaJ] => 60,66
[Czas] => 2017-07-10 08:01:42
[FromAgency] => 1
[Ilosc] => 1
[ProdKod] => 2322501
[RecNo] => 3163466
[Status] =>
[TowKod] => 205 658
[TowNaz] => HAM.KLOCKI /P/CORSA 01-
[Typ] => Z
[VAT] => 23
[WazneDni] => 5
)
However, when there is only one item on the order it goes deeper, returns only an object, not an array:
stdClass Object
(
[Cena] => 60,66
[CenaJ] => 60,66
[Czas] => 2017-07-10 08:01:42
[FromAgency] => 1
[Ilosc] => 1
[ProdKod] => 2322501
[RecNo] => 3163466
[Status] =>
[TowKod] => 205 658
[TowNaz] => HAM.KLOCKI /P/CORSA 01-
[Typ] => Z
[VAT] => 23
[WazneDni] => 5
)
I am trying to extract a table of items in this order, and everything is great until there is more than 2 items. Here is the exmaple of my code, I use count() to count how many items are there, to create a loop for a specific numer of rows in the table:
$tablica_zam=($buforinfo->GetOrdersResult->BuforInfo);
print_r($buforinfo->GetOrdersResult->BuforInfo);
$count= count((array)$tablica_zam);
echo"</br> Ilość pozycji w buforze zamówień :";
print_r($count);
echo "</br>";
$usun=array();
for ($i=0;$i<$count;$i++){
echo"<tr><td>";
print_r($buforinfo->GetOrdersResult->BuforInfo[$i]->ProdKod);
echo"</td><td>";
print_r($buforinfo->GetOrdersResult->BuforInfo[$i]->TowKod);
echo"</td><td>";
print_r($buforinfo->GetOrdersResult->BuforInfo[$i]->TowNaz);
echo"</td><td>";
print_r($buforinfo->GetOrdersResult->BuforInfo[$i]->Ilosc);
echo"</td><td>";
But it doesn't work when there is only one item, cause it is counting deeper items and returns 13, whole code has no application. Could you please give me some hints or solution on how to handle this exception?
Thanks in advance.