note 7880 deleted from function.in-array by jimw

From: Date: Fri, 07 Dec 2001 21:06:27 +0000
Subject: note 7880 deleted from function.in-array by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-21961@lists.php.net to get a copy of this message
It's worth noting that PHP4 will generate the warning message "Wrong datatype for second argument in call to in_array()" during execution if the array you pass to in_array() is undefined, instead of just returning false. In other words if there is a potential that your array won't have values inserted into it by the time it's sent to in_array(), be sure to initialize it with an empty array to avoid nasty error messages appearing in your pretty PHP pages: For example, a lurking disaster: -------------------------------------- if ($sometimes == "true") { $array[] = "something"; } in_array("something" $array); // statement above may generate warning The safe way: --------------------------------------- $array = array (); if ($sometimes == "true") { $array[] = "something"; } in_array("something", $array); // won't ever generate a warning

« previous php.notes (#21961) next »