note 118247 deleted from function.array-key-exists by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 20:46:10 +0000 |
| Subject: | note 118247 deleted from function.array-key-exists by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218771@lists.php.net to get a copy of this message | ||
Note Submitter: Venkata Subbaraju
----
array_key_exists perfect for $_GET .
As there will be browser level restriction on length of URL , number of keys in $_GET global
variable will be very limited . So array_key_exists will not cause any performance overhead in this
context . isset function can be conveniently ignored while handling $_GET variable.
But for $_POST , the max array size has to be configure in server PHP configuration . So cannot rely
on array_key_exists for $_POST if max array size is not optimized .
Here is an example with array_key_exists switching between content-types :
if(array_key_exists('format',$_GET))
{
if($_GET['format']=="json")
{
header('Content-Type: application/json');
}
else{
//handle any other format whitelisted for the application
}
}
else {
error_log("format parameter missing . using default html format");
header('Content-Type: text/html');
}