-2

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

7
  • 1
    Have you tried anything? Or just want codes? Commented Aug 30, 2017 at 8:44
  • I tried array_combine(), but that's just support two arrays Commented Aug 30, 2017 at 8:45
  • 1
    Try this php.net/manual/en/function.array-map.php Commented Aug 30, 2017 at 8:46
  • 2
    Then use simple foreach. Commented Aug 30, 2017 at 8:46
  • 2
    Or adapt your form so you get the desired result directly in $_POST... Commented Aug 30, 2017 at 8:49

1 Answer 1

3

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

}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.