note 16451 rejected from function.eval by zak

From: Date: Wed, 31 Oct 2001 11:05:08 +0000
Subject: note 16451 rejected from function.eval by zak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-19697@lists.php.net to get a copy of this message
Hello! I was asked how to solve this problem: <br> "How would I turn a string like "this string text blah" into 4 different variables? e.g. $var1=this, $var2=string, etc. etc....?" <br> The solution is: <? $string = "this string text blah"; $array = explode (" ", $string); for ($i = 0; $i < count($array); $i++) { $val = $array[$i]; $j = $i+1; eval ("\$var$j = \$val;"); } echo "$var1, $var2, $var3, $var4"; ?> will print: this, string, text, blah Happy codding! buddy (Lukas Kyzlink)

« previous php.notes (#19697) next »