note 118170 added to function.array-intersect-key
| From: | Mr.L | Date: | Tue, 20 Oct 2015 04:33:57 +0000 |
| Subject: | note 118170 added to function.array-intersect-key | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203985@lists.php.net to get a copy of this message | ||
The $_GET array is:
print_r($_GET);
Array
(
[page] => 1
[keywords] => something
[search_in_description] => yes
[sort] => up
)
I would like to only allow the following keys, and want it in this particular order:
$allowed_array = array(
'keywords',
'search_in_description',
'page',
'sort'
);
$sorted_array = array_intersect_key($_GET, array_flip($allowed_array));
Then I get this:
print_r($sorted_array);
Array
(
[page] => 1
[keywords] => something
[search_in_description] => yes
[sort] => up
)
And below is what I hoped to get:
Array
(
[keywords] => something
[search_in_description] => yes
[page] => 1
[sort] => up
)
Can anyone tell me what I am doing wrong or what I should do in order to achieve what want?
Thanks.
----
Server IP: 72.52.91.14
Probable Submitter: 50.135.185.80
----
Manual Page -- http://php.net/manual/en/function.array-intersect-key.php
Edit -- https://master.php.net/note/edit/118170
Del: integrated -- https://master.php.net/note/delete/118170/integrated
Del: useless -- https://master.php.net/note/delete/118170/useless
Del: bad code -- https://master.php.net/note/delete/118170/bad+code
Del: spam -- https://master.php.net/note/delete/118170/spam
Del: non-english -- https://master.php.net/note/delete/118170/non-english
Del: in docs -- https://master.php.net/note/delete/118170/in+docs
Del: other reasons-- https://master.php.net/note/delete/118170
Reject -- https://master.php.net/note/reject/118170
Search -- https://master.php.net/manage/user-notes.php