duangouyan3328 2017-08-30 08:41
浏览 8
已采纳

php数组合3个数组[关闭]

will be get 3 array $_POST array.

$_POST["name"]=> array (
    [0] => product_1
    [1] => product_2
    [2] => product_3
)


$_POST["content"]=> array (
    [0] => content_1
    [1] => content_2
    [2] => content_3
)


$_POST["price"]=> array (
    [0] => 100
    [1] => 200
    [2] => 300
)

I need to fetch it and add to mysql. So, I think that need to combine 3 array to one array.

so I need get this format? and how can I do? :

$array =>(
    [0] => (product_1,content_1,100)
    [1] => (product_2,content_2,200)
    [2] => (product_3,content_3,300)
)

I tried array_combine(), but that's just support two arrays

  • 写回答

1条回答 默认 最新

  • dongren4099 2017-08-30 09:03
    关注

    simple use foreach

    $new_array=array(); //create new array 
    
    foreach($_POST['name'] as $key=>$val){ //loop any one of post 
    
     $new_array[]=array($_POST['name'][$key],$_POST['content'][$key],$_POST['price'][$key]); //create new array with the help of $key
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?