二维数组转为一维数组。希望能帮到大家、、、

起初的数组是这样的:

array(3) {
  [0] => array(2) {
    [0] => array(16) {
      ["rec_id"] => string(1) "1"
      ["order_id"] => string(1) "1"
      ["goods_id"] => string(2) "18"
      ["goods_name"] => string(30) "写作业不用妈妈操心了"
      ["goods_sn"] => string(9) "ECS000018"
      ["product_id"] => string(1) "0"
      ["goods_number"] => string(1) "1"
      ["market_price"] => string(4) "0.00"
      ["goods_price"] => string(4) "0.00"
      ["goods_attr"] => string(0) ""
      ["send_number"] => string(1) "1"
      ["is_real"] => string(1) "1"
      ["extension_code"] => string(0) ""
      ["parent_id"] => string(1) "0"
      ["is_gift"] => string(1) "0"
      ["goods_attr_id"] => string(0) ""
    }
    [1] => array(16) {
      ["rec_id"] => string(1) "2"
      ["order_id"] => string(1) "1"
      ["goods_id"] => string(2) "12"
      ["goods_name"] => string(15) "恐龙寻宝记"
      ["goods_sn"] => string(9) "ECS000012"
      ["product_id"] => string(1) "0"
      ["goods_number"] => string(1) "1"
      ["market_price"] => string(4) "0.00"
      ["goods_price"] => string(4) "0.00"
      ["goods_attr"] => string(0) ""
      ["send_number"] => string(1) "1"
      ["is_real"] => string(1) "1"
      ["extension_code"] => string(0) ""
      ["parent_id"] => string(1) "0"
      ["is_gift"] => string(1) "0"
      ["goods_attr_id"] => string(0) ""
    }
  }
  [1] => array(1) {
    [0] => array(16) {
      ["rec_id"] => string(1) "4"
      ["order_id"] => string(1) "3"
      ["goods_id"] => string(2) "18"
      ["goods_name"] => string(30) "写作业不用妈妈操心了"
      ["goods_sn"] => string(9) "ECS000018"
      ["product_id"] => string(1) "0"
      ["goods_number"] => string(1) "1"
      ["market_price"] => string(4) "0.00"
      ["goods_price"] => string(4) "0.00"
      ["goods_attr"] => string(0) ""
      ["send_number"] => string(1) "0"
      ["is_real"] => string(1) "1"
      ["extension_code"] => string(0) ""
      ["parent_id"] => string(1) "0"
      ["is_gift"] => string(1) "0"
      ["goods_attr_id"] => string(0) ""
    }
  }
  [2] => array(2) {
    [0] => array(16) {
      ["rec_id"] => string(1) "6"
      ["order_id"] => string(1) "4"
      ["goods_id"] => string(1) "6"
      ["goods_name"] => string(21) "小猪唏哩呼噜下"
      ["goods_sn"] => string(9) "ECS000006"
      ["product_id"] => string(1) "0"
      ["goods_number"] => string(1) "1"
      ["market_price"] => string(4) "3.73"
      ["goods_price"] => string(4) "3.11"
      ["goods_attr"] => string(0) ""
      ["send_number"] => string(1) "0"
      ["is_real"] => string(1) "1"
      ["extension_code"] => string(0) ""
      ["parent_id"] => string(1) "0"
      ["is_gift"] => string(1) "0"
      ["goods_attr_id"] => string(0) ""
    }
    [1] => array(16) {
      ["rec_id"] => string(1) "7"
      ["order_id"] => string(1) "4"
      ["goods_id"] => string(2) "10"
      ["goods_name"] => string(30) "动物小百科:爬行动物"
      ["goods_sn"] => string(9) "ECS000010"
      ["product_id"] => string(1) "0"
      ["goods_number"] => string(1) "1"
      ["market_price"] => string(4) "4.96"
      ["goods_price"] => string(4) "4.13"
      ["goods_attr"] => string(0) ""
      ["send_number"] => string(1) "0"
      ["is_real"] => string(1) "1"
      ["extension_code"] => string(0) ""
      ["parent_id"] => string(1) "0"
      ["is_gift"] => string(1) "0"
      ["goods_attr_id"] => string(0) ""
    }
  }
}

 

预期的结果是

array(5) {
  [0] => array(16) {
    ["rec_id"] => string(1) "6"
    ["order_id"] => string(1) "4"
    ["goods_id"] => string(1) "6"
    ["goods_name"] => string(21) "小猪唏哩呼噜下"
    ["goods_sn"] => string(9) "ECS000006"
    ["product_id"] => string(1) "0"
    ["goods_number"] => string(1) "1"
    ["market_price"] => string(4) "3.73"
    ["goods_price"] => string(4) "3.11"
    ["goods_attr"] => string(0) ""
    ["send_number"] => string(1) "0"
    ["is_real"] => string(1) "1"
    ["extension_code"] => string(0) ""
    ["parent_id"] => string(1) "0"
    ["is_gift"] => string(1) "0"
    ["goods_attr_id"] => string(0) ""
  }
  [1] => array(16) {
    ["rec_id"] => string(1) "7"
    ["order_id"] => string(1) "4"
    ["goods_id"] => string(2) "10"
    ["goods_name"] => string(30) "动物小百科:爬行动物"
    ["goods_sn"] => string(9) "ECS000010"
    ["product_id"] => string(1) "0"
    ["goods_number"] => string(1) "1"
    ["market_price"] => string(4) "4.96"
    ["goods_price"] => string(4) "4.13"
    ["goods_attr"] => string(0) ""
    ["send_number"] => string(1) "0"
    ["is_real"] => string(1) "1"
    ["extension_code"] => string(0) ""
    ["parent_id"] => string(1) "0"
    ["is_gift"] => string(1) "0"
    ["goods_attr_id"] => string(0) ""
  }
  [2] => array(16) {
    ["rec_id"] => string(1) "4"
    ["order_id"] => string(1) "3"
    ["goods_id"] => string(2) "18"
    ["goods_name"] => string(30) "写作业不用妈妈操心了"
    ["goods_sn"] => string(9) "ECS000018"
    ["product_id"] => string(1) "0"
    ["goods_number"] => string(1) "1"
    ["market_price"] => string(4) "0.00"
    ["goods_price"] => string(4) "0.00"
    ["goods_attr"] => string(0) ""
    ["send_number"] => string(1) "0"
    ["is_real"] => string(1) "1"
    ["extension_code"] => string(0) ""
    ["parent_id"] => string(1) "0"
    ["is_gift"] => string(1) "0"
    ["goods_attr_id"] => string(0) ""
  }
  [3] => array(16) {
    ["rec_id"] => string(1) "1"
    ["order_id"] => string(1) "1"
    ["goods_id"] => string(2) "18"
    ["goods_name"] => string(30) "写作业不用妈妈操心了"
    ["goods_sn"] => string(9) "ECS000018"
    ["product_id"] => string(1) "0"
    ["goods_number"] => string(1) "1"
    ["market_price"] => string(4) "0.00"
    ["goods_price"] => string(4) "0.00"
    ["goods_attr"] => string(0) ""
    ["send_number"] => string(1) "1"
    ["is_real"] => string(1) "1"
    ["extension_code"] => string(0) ""
    ["parent_id"] => string(1) "0"
    ["is_gift"] => string(1) "0"
    ["goods_attr_id"] => string(0) ""
  }
  [4] => array(16) {
    ["rec_id"] => string(1) "2"
    ["order_id"] => string(1) "1"
    ["goods_id"] => string(2) "12"
    ["goods_name"] => string(15) "恐龙寻宝记"
    ["goods_sn"] => string(9) "ECS000012"
    ["product_id"] => string(1) "0"
    ["goods_number"] => string(1) "1"
    ["market_price"] => string(4) "0.00"
    ["goods_price"] => string(4) "0.00"
    ["goods_attr"] => string(0) ""
    ["send_number"] => string(1) "1"
    ["is_real"] => string(1) "1"
    ["extension_code"] => string(0) ""
    ["parent_id"] => string(1) "0"
    ["is_gift"] => string(1) "0"
    ["goods_attr_id"] => string(0) ""
  }
}

 只需要用array_merge()函数;

代码见下文
$array=array();
foreach ($data as $k=>$v){
$array=array_merge($v,$array);
}
其中的$data就如代码片段1所示的变量。
posted @ 2018-05-23 20:27  东东东蔚  阅读(853)  评论(0编辑  收藏  举报