This doesn't make sense to me...

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
dysfunct
Forum Newbie
Posts: 2
Joined: Wed Oct 10, 2007 8:34 pm

This doesn't make sense to me...

Post by dysfunct »

I have some code in which there are a bunch of objects. The objects are in arrays. When checking one of the arrays for a number thats in a variable in an object, I cant seem to get the search to work. However I can get the search to work by putting in one instance of that variable. But then comparing the two shows they're both the same. I don't get how if they're both the same one works and one doesn't. This is from inside one of the foreach statements:

Code: Select all

if (in_array($val->onumber,$ponum))
	echo "FOUND VARIABLE";
	if (in_array(358737,$ponum))
	echo "FOUND THE LITERAL";
	if ($val->onumber == 358737)
	echo "WHYWHYWHY";
The output is FOUND THE LITERALWHYWHYWHY. Why will it find the value directly but not the variable, when it admits they're the same?

BTW, the in_array is just what I was using to check this. What I really want to do is an array_search, that was doing the same thing.

Any suggestions?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

my first instinct would be to use array_map(), maybe even write a wrapper function for it.
Post Reply