How to loop through the POST array in PHP

How to loop through the POST array in PHP, If you have lots of form fields and you want to automate the process of writing long and daunting sql queries, By starting with assigning post array to variables, after that writing long sql query by mapping table row to assigned variables. We can automate this process by using this code.

First we are checking for post array submit is set or not, after that initializing an array for fields and values, after that we are looping through foreach loop, assigning post array to $field variable and $value variable. After that we are assigning each individual value to an array. We can manipulate those arrays and build complex sql queries dynamically, after wards we can reuse this code in different queries.

if (isset($_POST['submit'])){
		$fields = array();
		$values = array();
		foreach($_POST as $field => $value) {
			$fields[] = $field;
			$values[] = $value;

		}
           print_r($fields);
           print_r($values);
}

Incoming search terms:

  • php post with looping
Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe