note 83896 added to function.array-key-exists

From: Date: Tue, 17 Jun 2008 10:54:49 +0000
Subject: note 83896 added to function.array-key-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-140529@lists.php.net to get a copy of this message
I saw some examples above for array_keys_exist() or functions to see if multiple keys exist in a given array and return false if any of them don't. Here is a simpler way to do this: <?php function array_keys_exist($keys,$array) { if (count (array_intersect($keys,array_keys($array))) == count($keys)) { return true; } } $array = array ('filename' => 'myfile', 'filesize' => 1234, 'filepath' => '/tmp/myfile'); $keys = array('filename','filesize','filepath'); echo array_keys_exist($keys,$array); //returns true $keys[] = "somethingelse"; echo array_keys_exist($keys,$array); //Returns false ?> ---- Server IP: 59.162.86.33 Probable Submitter: 122.163.77.150 ---- Manual Page -- http://www.php.net/manual/en/function.array-key-exists.php Edit -- https://master.php.net/note/edit/83896 Del: integrated -- https://master.php.net/note/delete/83896/integrated Del: useless -- https://master.php.net/note/delete/83896/useless Del: bad code -- https://master.php.net/note/delete/83896/bad+code Del: spam -- https://master.php.net/note/delete/83896/spam Del: non-english -- https://master.php.net/note/delete/83896/non-english Del: in docs -- https://master.php.net/note/delete/83896/in+docs Del: other reasons-- https://master.php.net/note/delete/83896 Reject -- https://master.php.net/note/reject/83896 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140529) next »