Yes, it's possible using variable variables:
foreach($_POST as $key => $value) {
$$key = $value;
}
or using extract:
extract($_POST);
But please be aware that doing this will introduce a potential security hole.
It's in fact like simulating PHP's register_globals directive, which introduces lots of security issues.
You could assign a subset of $_POST variables, this is a much safer way:
$keys = array('id', 'name', 'story', 'imgurl', 'thisAction');
foreach($keys as $key) {
$$key = $_POST[$key];
}
or using extract:
$whitelisted = array_intersect_key($_POST, array('id', 'name', 'story', 'imgurl', 'thisAction'));
extract($whitelisted);
$_POST['id']multiple times because that would be inefficient. Better to save a copy of the value returned by it.$ideverywhere?$id = isset($_POST['id']) ? $_POST['id'] : 0;and be done with it. Not sure how that would be more efficient, though. edit: slow again...