php将一维数组转换成二维数组

$fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry');

$fruit = array(
    array('key'=>'a', 'val'=>'apple'), 
    array('key'=>'b', 'val'=> 'banana'), 
    array('key'=>'c', 'val'=> 'cranberry')
);

$fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry');
 
$tmp = array();
reset($fruit);
while (list($key, $val) = each($fruit)) {
    $tmp[] = array('key'=>$key,'val'=>$val);
}
print_r($tmp);

 

    原文作者:qq_37138818
    原文地址: https://blog.csdn.net/qq_37138818/article/details/104901727
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞