0

我在下面有一些值:

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));

我需要帮助来制作像 array(11,12,13)​​ 这样的数组。知道吗?

4

4 回答 4

0

试试看http://www.php.net/manual/en/function.str-split.phpstr_split _

$str = "111213";

$array = str_split($str, 2);

print_r($array);

输出 :

Array
(
    [0] => 11
    [1] => 12
    [2] => 13
)
于 2013-11-14T06:35:49.903 回答
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);
于 2013-11-14T06:36:01.197 回答
0

You can use explode here. split is deprecated in latest version.

$str = "11 12 13";
$array = explode(" ",$str);
于 2013-11-14T06:36:02.590 回答
0
$selected = "11 12 13";

print_r (explode(" ",$selected));
于 2013-11-14T06:40:03.353 回答