Skip to content

Instantly share code, notes, and snippets.

@YuvrajKhavad
Last active November 5, 2020 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YuvrajKhavad/6af9624f39ebdbddd575e9bc33821319 to your computer and use it in GitHub Desktop.
Save YuvrajKhavad/6af9624f39ebdbddd575e9bc33821319 to your computer and use it in GitHub Desktop.
Genreate dynamic php variable using foreach from array of form serialize data.
$selected_data = $_POST['selected_data'];
print_r($selected_data);
/*
// array formate
Array
(
[0] => Array
(
[name] => authorname
[value] => 201
)
[1] => Array
(
[name] => posttags
[value] => Tag5
)
)
*/
if(is_array($selected_data))
{
foreach($selected_data as $data)
{
${$data['name']} = $data['value'];
}
}
echo $authorname;
echo "</br>";
echo $posttags;
// output
201</br>Tag5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment