输入:
$string="cat, dog, pig, hello";
必需输出(动态)
$string1= cat;
$string2= dog;
$string3= pig;
$string4= hello;
在字符串中使用逗号后,该单词将成为新的子字符串。
答案 0 :(得分:2)
试试这个:
ng-class="{wm_clearfix3}"
答案 1 :(得分:1)
在PHP中使用extract函数
$string="cat, dog, pig, hello";
$stringArr = explode(",", $string); //Split strings to array using delimeter (,)
$newArr = [];
foreach ($stringArr as $key => $value) {
$newArr['string'.($key+1)] = trim($value); //Use trim to remove the unwanted spaces in your words after exploding
}
extract($newArr);
echo $string1; //cat
echo $string2; //dog
echo $string3; //pig
echo $string4; //hello
记住:您最终会创建太多变量!最好使用 数组为数组
答案 2 :(得分:0)
$string="cat, dog, pig, hello";
$Array = explode(',', $string);
print_r($Array );