Juliver Galleto
Juliver Galleto

Reputation: 9037

eliminate a specified post data on a post request array

I use this code to retrieve all the post request (refer below)

<?php
foreach ($_POST as $key => $value) {
    $body .= $key . ": " . $value . '<br>';
}
echo $body;
?>

and there is a post data named "adminemail" and "cat", now what i want is to eliminate those two and print all the post data except those two. How to do that? any suggestions, recommendations and ideas, would love to hear. Thank you in advance.

Upvotes: 0

Views: 35

Answers (2)

Sharanya Dutta
Sharanya Dutta

Reputation: 4021

The following should work:

<?php
$arr = array_diff_key($_POST, array("adminemail" => 0, "cat" => 0));
$body = ""; // You must have this line, or PHP will throw an "Undefined variable" notice
foreach($arr as $key => $value){
    $body .= $key . ": " . $value . "<br/>";
}
echo $body;
?>

Upvotes: 0

user557846
user557846

Reputation:

option 1

unset($_POST['adminemail'],$_POST['cat']);

option 2

<?php
foreach ($_POST as $key => $value) {
   if(!in_array($key,array('adminemail','cat'))){
       $body .= $key . ": " . $value . '<br>';
   }
}
echo $body;
?>

Upvotes: 1

Related Questions