i have an the following string from my database:
";5;78;27;56;66;71;"
how can I extract / explode into variables
$a = "5";
$b = "78";
$c = "27";
thank you for your help!
Reference: http://us1.php.net/explode
$data = ";5;78;27;56;66;71;";
$dataArr = explode(';',$data);
for($i = 0; $i < count($dataArr); $i++){
${'var'.$i} = $dataArr[$i];
}
Explode should return an array of values. Then you iterate through said values and dynamically assign a name to each one.
In my example code, you'll get $var1, $var2, $var3 and so on.
array_filter( explode(';', ";5;78;27;56;66;71;") );
The filter is to get rid of some empty values.
Gives you an array of the values:
Array ( [1] => 5 [2] => 78 [3] => 27 [4] => 56 [5] => 66 [6] => 71 )