note 21310 modified in function.in-array by danbrown

From: Date: Mon, 08 Jun 2009 21:47:53 +0000
Subject: note 21310 modified in function.in-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156532@lists.php.net to get a copy of this message
Sometimes, you might want to search values in array, that does not exist. In this case php will display nasty warning: Wrong datatype for second argument in call to in_array() . In this case, add a simple statement before the in_array function: <?php if (sizeof($arr_to_searchin) == 0 || !in_array($value, $arr_to_searchin)) { /*...*/ } ?> In this case, the 1st statement will return true, omitting the 2nd one. --was-- Sometimes, you might want to search values in array, that does not exist. In this case php will display nasty warning: Wrong datatype for second argument in call to in_array() . In this case, add a simple statement before the in_array function: if (sizeof($arr_to_searchin) == 0 || !in_array($value, $arr_to_searchin)) { ... } In this case, the 1st statement will return true, omitting the 2nd one. http://php.net/manual/en/function.in-array.php

« previous php.notes (#156532) next »