需要在数组结构中编辑

时间:2014-11-11 10:32:41

标签: php arrays

如何更改以下数组格式

Array ( [0] => Array ( [reviews] => data 1 [reviews 2] =>data 2 ))

这种格式。

 Array ( [0] => Array ([0] => Array([reviews] =>data 1) [1] => Array( [reviews 2] => data 2 ))

3 个答案:

答案 0 :(得分:0)

$newarr = array();
$i = 0;
foreach($array as $single){
    $newarr[$i] = $single;
    $i++;
}

试试这个

答案 1 :(得分:0)

尝试

$arr =  array (array('reviews' => 'data 1', 'reviews 2' =>'data 2' ));
foreach($arr[0] as $k=>$v){
  $newarr[0][] = array($k =>$v);
}
print_r($newarr);//Array ( [0] => Array ( [0] => Array ( [reviews] => data 1 ) [1] => Array ( [reviews 2] => data 2 ) ) ) 

答案 2 :(得分:0)

我说的5分钟,这是我的答案;)

$test = array ( 0 => array ( 'reviews' => 'data 1', 'reviews 2' => 'data 2' ));
$new_arr = array();
foreach($test as $key => $value) {
   foreach($value as $k => $v) {
      $new_arr[$key][][$k] = $v;
   }
}

print_r($new_arr);

输出:

Array ( [0] => Array ( [0] => Array ( [reviews] => data 1 ) [1] => Array ( [reviews 2] => data 2 ) ) )

我是这样做的,所以当你看到它时你可能会理解。希望你会的!