note 118170 deleted from function.array-intersect-key by cmb
| From: | cmb@php.net | Date: | Wed, 16 Dec 2015 15:15:55 +0000 |
| Subject: | note 118170 deleted from function.array-intersect-key by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-204406@lists.php.net to get a copy of this message | ||
Note Submitter: Mr. L
----
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.