js:
//如果数组元素不包含字符“,”:
var a = [1,3,4,5,[6,7,9],[2],[5]];
a = a.join(",").split(",");
php:
//采用递归实现:
function array_multi2single($array) {
static $result_array = array();
foreach($array as $value) {
if(is_array($value)) {
array_multi2single($value);
} else {
$result_array[] = $value;
}
}
return $result_array;
}
添加
@毛杭军
提供的方法:
//采用array_walk_recursive
$a1=array("a"=>"Cat","b"=>"Dog");
$a2=array($a1,"1"=>"Bird","2"=>"Horse");
function put($value, $key) {
static $result = array();
$result[] = $value;
}
array_walk_recursive($a2, "put");