How to loop through the POST array in PHP - Coding Cyber

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.

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


php post array traverse array in php form php loop through post variables php get post value from loop php foreach post array php assigning variables to post array php assigning values from a post array based off input values loop through POST variables in php loop through post values loop the $post value
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: