我在array
上使用PHP
并发现问题,因为我有一组数组
$x = array(array("Ram","shyam"),array("Hari","Gopal"),array("Rama","Bidhya"))
现在我想把这个数组转换成这样的
array(array("Ram","Hari","Rama"),array("Shyam","Gopal","Bidhya"))
谢谢
答案 0 :(得分:1)
试试这个
array_unshift()
函数将新元素插入到数组中。新数组值将插入数组的开头。
$x = array(array("Ram","shyam"),array("Hari","Gopal"),array("Rama","Bidhya"));
function transpose($array) {
array_unshift($array, null);
return call_user_func_array('array_map', $array);
}
$out = transpose($x);
echo '<pre>';
print_r($out);
<强>结果强>
Array
(
[0] => Array
(
[0] => Ram
[1] => Hari
[2] => Rama
)
[1] => Array
(
[0] => shyam
[1] => Gopal
[2] => Bidhya
)
)