note 127042 added to function.array-intersect

From: Date: Mon, 09 May 2022 17:44:02 +0000
Subject: note 127042 added to function.array-intersect
Groups: php.notes 
Request: Send a blank email to php-notes+get-218366@lists.php.net to get a copy of this message
I use array_intersect for a quick check of $_GET parameters; <?php declare(strict_types=1) $_params = ['cust_id','prod_id']; $_params_check = array_intersect(array_keys($_GET),$_params); if(count($_params_check) !== count($_params)) { header("HTTP/1.1 400 Bad Request"); die(); } ?> the file will die with a 400 error if cust_id or prod_id or both are missing from $_GET. But i could be used on $_POST and $_REQUEST as well obviously. ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.47 (proxied: 83.97.82.108) ---- Manual Page -- https://php.net/manual/en/function.array-intersect.php Edit -- https://main.php.net/note/edit/127042 Del: integrated -- https://main.php.net/note/delete/127042/integrated Del: useless -- https://main.php.net/note/delete/127042/useless Del: bad code -- https://main.php.net/note/delete/127042/bad+code Del: spam -- https://main.php.net/note/delete/127042/spam Del: non-english -- https://main.php.net/note/delete/127042/non-english Del: in docs -- https://main.php.net/note/delete/127042/in+docs Del: other reasons-- https://main.php.net/note/delete/127042 Reject -- https://main.php.net/note/reject/127042 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#218366) next »