note 111072 added to reserved.variables.post
| From: | ukaszGieratowski | Date: | Fri, 11 Jan 2013 13:37:07 +0000 |
| Subject: | note 111072 added to reserved.variables.post | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192928@lists.php.net to get a copy of this message | ||
If we have form Like that:
<form>
<input name="bob" value="1">
<input name="ala[ola][ela]" value="2">
</form>
And We will send the form, we will get multidimensional array:
$_POST = Array(
[bob] => 1
[ala] => Array(
[ola] => Array(
[ela]=>2
)
)
)
But when we have only array and want to make form, there is usefull function:
<?php
function extractPost($array, $parent_key=null){
$ret = array();
foreach($array as $key=>$val){
if(is_array($val)){
$children = extractPost($array[$key], $parent_key.$key.'][');
$ret = array_merge($ret, $children);
} else {
$ret[$parent_key.$key]=$val;
}
}
return $ret;
}
?>
Example:
<?php
$array = array('bob'=>1,
'ala'=>array('ola'=>array('ela'=>2)));
print_r($array);
print_r(extractPost($array));
?>
Output:
Array(
[bob] => 1
[ala] => Array(
[ola] => Array(
[ela] => 2
)
)
)
Array(
[bob] => 1
[ala][ola][ela] => 2
)
----
Server IP: 69.147.83.199
Probable Submitter: 85.202.52.57
----
Manual Page -- http://php.net/manual/en/reserved.variables.post.php
Edit -- https://master.php.net/note/edit/111072
Del: integrated -- https://master.php.net/note/delete/111072/integrated
Del: useless -- https://master.php.net/note/delete/111072/useless
Del: bad code -- https://master.php.net/note/delete/111072/bad+code
Del: spam -- https://master.php.net/note/delete/111072/spam
Del: non-english -- https://master.php.net/note/delete/111072/non-english
Del: in docs -- https://master.php.net/note/delete/111072/in+docs
Del: other reasons-- https://master.php.net/note/delete/111072
Reject -- https://master.php.net/note/reject/111072
Search -- https://master.php.net/manage/user-notes.php