I am trying to retrieve the last names of the orders placed.
code:
for ($x = 0; $x < 25; ++$x) {
if (($orders[$x]['paymentStatus'] == 'paid') || ($orders[$x]['paymentIsPost'] == TRUE)) {
echo '<pre>';
print_r($orders[$x]['lastname']);
echo '</pre>';
}
}
question: code is not showing me the first lastname in the array actually the name that is in position $orders[0]. I thought that pre-incrementing the variable like this ++$x like this would solve the problem. To bad thats not the case. Any tips?
Update output:
[1]""
[2]""
[3]""
[4]""
[5]""
Not sharing lastnames, which is also not relevant.
1 Answer 1
try the following to confirm which element of the array you are displaying (and the value of $x
for($x = 0; $x < 25 ; $x++){
if(($orders[$x]['paymentStatus'] == 'paid') || ($orders[$x]['paymentIsPost'] == true)){
echo '<pre>';
--print_r($orders[$x]['lastname']);
echo '['.$x.']'.$orders[$x]['lastname'];
echo '</pre>';
}
}
answered Feb 23, 2016 at 15:06
-
See the opcoming update to the post, it does not display [0] it starts at [1]izk– izk2016年02月23日 15:11:50 +00:00Commented Feb 23, 2016 at 15:11
-
See VolkerK's request for an output of $orders just to make sure what data is in there as that could be the source of your problemDave– Dave2016年02月23日 15:12:09 +00:00Commented Feb 23, 2016 at 15:12
-
do a
print_r($orders)
prior to thefor
loop so we can see the data that is in there. I suspect that your0
element isn'tpaid
orpaymentIsPost
which is why it isn't displaying, or there isn't a0
elementDave– Dave2016年02月23日 15:15:51 +00:00Commented Feb 23, 2016 at 15:15 -
your code gave me insight in the solution thank you.izk– izk2016年02月23日 15:20:54 +00:00Commented Feb 23, 2016 at 15:20
-
so it was
$x++
instead of++$x
or another problem?Santa's helper– Santa's helper2016年02月23日 15:49:43 +00:00Commented Feb 23, 2016 at 15:49
lang-php
$x++
var_export($orders);
?