note 13500 deleted from function.explode by jimw

From: Date: Fri, 07 Dec 2001 21:24:18 +0000
Subject: note 13500 deleted from function.explode by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22005@lists.php.net to get a copy of this message
I have a common situation that recently caused some problems, here's my solution. I frequently do: $arrname = explode(",", $mystring); foreach($arrname as $a) . . . The problem is if $mystring only has one element then $arrname isn't a string and foreach() complains. So if you are ever using explode and you NEED to have an array do: $arrname = explode(",", $mystring); if(!is_array($arrname)) $arrname = array($mystring); That if statement will make sure you always get an array. -Keith http://www.leverworks.com

« previous php.notes (#22005) next »