note 13500 added to function.explode.php

From: Date: Tue, 19 Jun 2001 16:17:48 +0000
Subject: note 13500 added to function.explode.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-14444@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 http://www.php.net/manual/en/function.explode.php

« previous php.notes (#14444) next »