Home > Mobile >  Is it possible to convert PHP array to POST Request?
Is it possible to convert PHP array to POST Request?

Time:10-06

I have an array like this (around 50 items).

$data = array();
$data['customer_id'] = '1';
$data['cus_serno'] = '2';

Is it possible to convert this to POST request like if I echo $_POST['customer_id'] it should display 1.

I already know that I can do something like below.

$_POST['customer_id'] = $data['customer_id'];
$_POST['cus_serno'] = $data['cus_serno'];

This will be time-consuming since I have around 50 items in the array.

CodePudding user response:

try this

foreach($data as $key => $val) {
  $_POST[$key] = $val;
}

it's assign your $array key as $_POST key and put your array value on it

CodePudding user response:

$_POST=$data;

You can just assign $data array to $_POST like $_POST=$data; but it will replace your existing post array

  • Related