Wrong datatype error

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
allasso
Forum Commoner
Posts: 28
Joined: Fri Nov 28, 2008 1:24 pm

Wrong datatype error

Post by allasso »

with this command...

if (array_search($item, $items_ordered_array) === FALSE) do something ;

I get this error:

Warning: array_search() [function.array-search]: Wrong datatype for second argument...

I have read the man page for array_search several times and I don't understand why this won't work. It even tells you to use ===.

Anyone know what is happening, and what to do to make it work?

BTW, it works okay on my test server which has PHP 5.2.4, but not on the internet server I am using which has PHP 5.2.13.. ??????

thanks, Allasso
Alkis
Forum Commoner
Posts: 31
Joined: Fri Mar 26, 2010 8:41 am

Re: Wrong datatype error

Post by Alkis »

By what I can understand from the error, it tells you that the second argument passed to array_search, in this case the $items_ordered_array, it is not an array.

The reason you get this warning on the production server and not on the test server, is maybe the production server is configured to display warnings, while the configuration on your test server is to hide them.

I suggest setting error_reporting on your php.ini to E_ALL | E_STRICT or only E_ALL is the recommended way to find those warning on the test server before uploading to your production server.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Wrong datatype error

Post by s.dot »

do print_r($items_ordered_array); and see what it is
Basically the error is complaining that $items_order_array is not an array
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
allasso
Forum Commoner
Posts: 28
Joined: Fri Nov 28, 2008 1:24 pm

Re: Wrong datatype error

Post by allasso »

yes, I testing before the array was initialized.

many thanks.
Post Reply