Home  >  Article  >  Backend Development  >  一个数组的转换

一个数组的转换

WBOY
WBOYOriginal
2016-06-23 14:10:191010browse

我想把这个数组转换一下,$array = array('name'=>array('aaaa','bbbb','ccccc'),'uid'=>array('1111','2222','3333'));

这样的效果
$k=array(array('name'=>'aaaa','uid'=>'1111'),array('name'=>'bbbb','uid'=>'2222'),array('name'=>'cccc','uid'=>'3333'));


回复讨论(解决方案)

$key=array_keys($array);foreach($array['name'] as $k=>$v){       $ar[]=array($v,$array['uid'][$k]);}foreach($ar as &$v) $v=array_combine($key,$v);print_r($ar);

$array = array('name'=>array('aaaa','bbbb','ccccc'),'uid'=>array('1111','2222','3333'));foreach($array as $k=>$r){  foreach($r as $i=>$v) $ar[$i][$k] = $v;}print_r($ar);
Array
(
    [0] => Array
        (
            [name] => aaaa
            [uid] => 1111
        )

    [1] => Array
        (
            [name] => bbbb
            [uid] => 2222
        )

    [2] => Array
        (
            [name] => ccccc
            [uid] => 3333
        )

)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn