note 83896 deleted from function.array-key-exists by crell

From: Date: Wed, 29 Jun 2022 20:40:44 +0000
Subject: note 83896 deleted from function.array-key-exists by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218753@lists.php.net to get a copy of this message
Note Submitter: jacobsingh at gmail dot com ---- 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 ?>

« previous php.notes (#218753) next »