PHP Classes

File: php/getPostRequest.php

Recommend this page to a friend!
  Classes of bamigboye biodun   Logical Functions   php/getPostRequest.php   Download  
File: php/getPostRequest.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Logical Functions
General-purpose PHP and JavaScript functions
Author: By
Last change:
Date: 1 year ago
Size: 960 bytes
 

Contents

Class file image Download
<?php
     
function getPostRequest(Array $postKeys){
       
       
$output=[];
       
$errorLog=[];
        foreach (
$postKeys as $key ) {
            if(!
array_key_exists($key, $_POST)){
           
           
array_push($errorLog,$key);
            continue;
            }
           
$data = $_POST[$key];
            
$output[$key]=$data;
           }
           return [
'data' => $output, 'error' =>$errorLog];
      }


   
// -- Usage
getPostRequest(['name','email','keyNotPosted']);
// Return Value
[
'data' => [
   
'name' => 'Biodun Bamigboye',
   
'email' => 'biodunbamigboye@eportalnet.com'
],
'error' => ['keyNotPosted']
];
     
/*
Author : Biodun Bamigboye

This function receives an indexed array of post key indexes
and returns an associative array of entered data and index
array for keys with no data existing.
Note That data is subjected to further tests by you before
saving it to db

*/