note 16439 added to function.eval
| From: | buddy at www dot zabiny dot cz | Date: | Tue, 30 Oct 2001 17:52:44 +0000 |
| Subject: | note 16439 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-19612@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)
--
http://www.php.net/manual/en/function.eval.php
http://master.php.net/manage/user-notes.php?action=edit+16439
http://master.php.net/manage/user-notes.php?action=delete+16439
http://master.php.net/manage/user-notes.php?action=reject+16439