我有以下几个值:
11 12 13。
我需要使用此值创建一个数组。 阵列(11,12,13);
我在下面尝试了以下代码:
$selected is the variable that contain the value 11 12 13 //Special Instruction
foreach($selected as $key=>$val)
{
$sel.=$val;
$sel.=",";
}
$str = rtrim($sel,',');
// echo $str;
$shortlist = array_map('trim', explode(',',$str));
我需要帮助来创建一个像数组一样的数组(11,12,13)。任何想法?
答案 0 :(得分:0)
尝试str_split
,请参阅http://www.php.net/manual/en/function.str-split.php
$str = "111213";
$array = str_split($str, 2);
print_r($array);
输出:
Array
(
[0] => 11
[1] => 12
[2] => 13
)
答案 1 :(得分:0)
$values = explode(' ', "11 12 13");
// if there is no space, you can do it like this
$strLen = strlen($string);
$i = 0;
while($i < $strLen) {
$myArr[] = substr($string, $i, 2);
$i += 2;
}
print_r($myArr);
答案 2 :(得分:0)
答案 3 :(得分:0)
$selected = "11 12 13";
print_r (explode(" ",$selected));