Page 1 of 1
Newbie array key extract question.
Posted: Fri Jun 19, 2009 6:45 pm
by LDusan
Simply put, why this won't work?
Code: Select all
$val="3";
$aarray[]="A";
$aarray[]="B";
$aarray[]="C";
$aarray[]="D";
echo $array[$val];
Can someone please help?
Re: Newbie array key extract question.
Posted: Fri Jun 19, 2009 6:54 pm
by requinix
Look. Really. Look at it.
Re: Newbie array key extract question.
Posted: Fri Jun 19, 2009 6:57 pm
by LDusan
Typography error. I can't believe it, it did not work in one bigger project, so I simplified.
Thanks anyway.
Re: Newbie array key extract question.
Posted: Fri Jun 19, 2009 7:30 pm
by requinix
So... was that the problem then? Or something else?
Moral: avoid "simplifying" code when posting for help because you might accidentally change stuff. If you don't know the source of the problem then how do you know that the simplified code will have the same problem too?
Re: Newbie array key extract question.
Posted: Fri Jun 19, 2009 7:37 pm
by LDusan
I was building one non-OOP shopping cart, and figuring out how to deduct prices of the removed articles from total price.
It just did not work because I accidentally first unsetted the array element and then called it elsewhere. I was looking for the error in the wrong part of the code.
Thanks a lot anyway, I appreciate it.