Hi guys, really cracking my head why i can't loop through this array...
I'm calling a webservice which returns result in an array but if there is only one result i can't get an index for that array.. see below the code var_dump output which differs..
-- code ---
if (!$tx_elem == NULL) {
foreach($tx_elem as $name => $value){
echo "<tr>";
echo '<td align="left" valign="top" class="grey12">'.date("M d Y",strtotime($value['TX-ELEM-DATE'])).'</td>';
echo '<td align="left" valign="top" class="grey12">'.$value['TX-ELEM-VAL'].' '.$value['TX-ELEM-TYPE'].'</td>';
echo "</tr>";
}
unset($value);
var_dump($tx_elem);
var_dump($name);
}
if there is only one transaction .. the var dump for $tx_elem output like below
array
'TX-ELEM-DATE' => string '20080330' (length=8)
'TX-ELEM-TYPE' => string 'Points earned' (length=13)
'TX-ELEM-PCI' => string 'NZNL' (length=4)
'TX-ELEM-PCD' => string 'TEST CARD' (length=34)
'TX-ELEM-VAL' => string '23' (length=2)
$name output like this ---
string 'TX-ELEM-VAL' (length=11)
but if there is more than one result then the $tx_elem return
array
0 =>
array
'TX-ELEM-DATE' => string '20070521' (length=8)
'TX-ELEM-TYPE' => string 'Points earned' (length=13)
'TX-ELEM-PCI' => string 'CCTI' (length=4)
'TX-ELEM-PCD' => string 'CCTI TESTING USAGE' (length=18)
'TX-ELEM-VAL' => string '69' (length=2)
1 =>
array
'TX-ELEM-DATE' => string '20070707' (length=8)
'TX-ELEM-TYPE' => string 'Points earned' (length=13)
'TX-ELEM-PCI' => string 'CCTI' (length=4)
'TX-ELEM-PCD' => string 'CCTI TESTING USAGE' (length=18)
'TX-ELEM-VAL' => string '100' (length=3)
2 =>
array
'TX-ELEM-DATE' => string '20070707' (length=8)
'TX-ELEM-TYPE' => string 'Points used' (length=11)
'TX-ELEM-PCI' => string 'CCTI' (length=4)
'TX-ELEM-PCD' => string 'CCTI TESTING USAGE' (length=18)
'TX-ELEM-VAL' => string '-100' (length=4)
3 =>
array
'TX-ELEM-DATE' => string '20070821' (length=8)
'TX-ELEM-TYPE' => string 'Points earned' (length=13)
'TX-ELEM-PCI' => string 'CCTI' (length=4)
'TX-ELEM-PCD' => string 'CCTI TESTING USAGE' (length=18)
'TX-ELEM-VAL' => string '52' (length=2)
and the $name returns
int 15
how can i check if the array has any index or not...? otherwise the distplay of the result fails