I'm trying to change given $_POST data to variable format, here is my code:
<?php
$_POST["abc"]=2;
$post = array("abc");
foreach($post as $field) {
global $field;
$field = $_POST[$field];
}
echo $abc;
?>
but when I'm trying to run this code, I only get:
PHP Notice: Undefined variable: abc in /var/www/ on line 8
How can I change chosen POST variables in loop to normal variables? (eg. $_POST["abc"] to $abc)
Use the extract function
extract($_POST)
You can tried with PHP variable variable.
<?php
$_POST["abc"]=2;
$post = array("abc");
foreach($post as $field) {
global $$field;
$$field = $_POST[$field];
}
echo $abc;
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With