从多个数组获得结果?

时间:2011-05-13 08:49:02

标签: php multidimensional-array

$row_properties = array(
     "Header 1"=>array("width"=>20,"align"=>'C',"colors"=>array(100,220,255)),
     "Header 2"=>array("width"=>20,"align"=>'C',"colors"=>array(100,220,255)),
     "Header 3"=>array("width"=>20,"align"=>'C',"colors"=>array(100,220,255)),
);

我尝试将widthsalgins colors作为这样的数组

$widths = array(20,20,20);
$aligns  = array("C","C","C")
$colors  array(array(100,220,255),array(100,220,255),array(100,220,255));

3 个答案:

答案 0 :(得分:3)

$widths = $aligns = $colors = array();
foreach ($row_properties as $prop) {
  $widths[] = $prop['width'];
  $aligns[] = $prop['align'];
  $colors[] = $prop['color'];
}

答案 1 :(得分:1)

$widths = array();
$aligns = array();
$colors = array();

foreach($row_properties as $property) {
    $widths[] = $property['width'];
    $aligns[] = $property['align'];
    $colors[] = $property['colors'];
}

就是这样:))

答案 2 :(得分:1)

$widths = array();
$aligns  = array();
foreach($row_properties as $row){
   $widths[] = $row['width'];
   $aligns[] = $row['align'];
}