Newbie array key extract question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LDusan
Forum Commoner
Posts: 45
Joined: Sun Mar 08, 2009 5:03 am
Location: Belgrade, Serbia

Newbie array key extract question.

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Newbie array key extract question.

Post by requinix »

Code: Select all

$aarray[]="D";
echo $array[$val];
Look. Really. Look at it.
LDusan
Forum Commoner
Posts: 45
Joined: Sun Mar 08, 2009 5:03 am
Location: Belgrade, Serbia

Re: Newbie array key extract question.

Post by LDusan »

Typography error. I can't believe it, it did not work in one bigger project, so I simplified.

Thanks anyway.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Newbie array key extract question.

Post 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?
LDusan
Forum Commoner
Posts: 45
Joined: Sun Mar 08, 2009 5:03 am
Location: Belgrade, Serbia

Re: Newbie array key extract question.

Post 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.
Post Reply