在PHP中使用多个数组

时间:2015-06-08 08:36:45

标签: php arrays multidimensional-array foreach

我有一个这样的数组:

$ optionarray:

 array(3) { [0]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } [1]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } [2]=> array(3) { [0]=> string(19) "Formation" [1]=> string(1) "1" [2]=> string(1) "0" } }

$ dataarray:

 array(2) { [0]=> array(3) { [0]=> string(23) "Physical room" [1]=> int(1) [2]=> string(7) "12,00 €" } [1]=> array(3) { [0]=> string(26) "user desk" [1]=> int(4) [2]=> string(7) "40,00 €" } }

$ fullarray:

 array(5) { [0]=> array(3) { [0]=> string(23) "Physical room" [1]=> int(1) [2]=> string(7) "12,00 €" } [1]=> array(3) { [0]=> string(26) "user desk" [1]=> int(4) [2]=> string(7) "40,00 €" } [2]=> array(3) { [0]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } [1]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } [2]=> array(3) { [0]=> string(19) "Formation " [1]=> string(1) "1" [2]=> string(1) "0" } } [3]=> array(3) { [0]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } [1]=> array(3) { [0]=> string(19) "Formation" [1]=> string(1) "1" [2]=> string(1) "0" } [2]=> NULL } [4]=> array(3) { [0]=> array(3) { [0]=> string(19) "Formation " [1]=> string(1) "1" [2]=> string(1) "0" } [1]=> NULL [2]=> NULL } }

我的fullarray 没有独特的结构,我只想将 $ optionarray 添加到 $ dataarray 并迭代 $ fullarray

我的代码:

$data[0] = array('Physical room', $nbprice, $totalprice);
$data[1] = array('user desk', $nbuser, $totaluserprice );

$i=2;

for($j=0;$j<count($optionsdata);$j++){
       $data[$i]=array($optionsdata[$j],$optionsdata[$j+1],$optionsdata[$j+2]);
      $i=$i+1;
 }

如何继续创建 $ fullarray正确以进行迭代并显示每个值?

预期输出:

 array(5){
                     [0]=>array(3){ [0]=> string(23) "Physical room" [1]=> int(1) [2]=> string(7) "12,00 €" } 
                     [1]=> array(3) { [0]=> string(26) "user desk" [1]=> int(4) [2]=> string(7) "40,00 €" }
                     [2]=> array(3) { [0]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } 
  [3]=> array(3) { [0]=> string(15) "Extension" [1]=>   string(1) "1" [2]=> string(2) "10" } 
                     [4]=> array(3) { [0]=> string(19) "Formation " [1]=> string(1) "1" [2]=> string(1) "0" }
   }

0 个答案:

没有答案