note 107141 added to function.array-keys

From: Date: Tue, 10 Jan 2012 17:21:49 +0000
Subject: note 107141 added to function.array-keys
Groups: php.notes 
Request: Send a blank email to php-notes+get-185521@lists.php.net to get a copy of this message
<?php /* A Function created by myself for checking multiple array keys For Example u got an Array like $_SESSION and u wanna know if the keys 'user','pass','email' and 'type' exists. */ function mKeyChecker($arr,$keys=array()) { if(count($keys) > 1) { $valid_keys = 0; foreach($keys as $key) { if(array_key_exists($key,$arr)) $valid_keys++; } if($valid_keys == count($keys)) { return true; } else { return false; } } else if(count($keys) == 1) { if(array_key_exists($key[0],$arr)) { return true; } else { return false; } } else { return false; } } // Execution Example if(mKeyChecker($_SESSION,array('id','user','email','type'))) { echo "is!"; } else { echo "not!"; } ?> ---- Server IP: 115.182.65.88 Probable Submitter: 79.235.146.210 (proxied: 79.235.146.210) ---- Manual Page -- http://www.php.net/manual/en/function.array-keys.php Edit -- https://master.php.net/note/edit/107141 Del: integrated -- https://master.php.net/note/delete/107141/integrated Del: useless -- https://master.php.net/note/delete/107141/useless Del: bad code -- https://master.php.net/note/delete/107141/bad+code Del: spam -- https://master.php.net/note/delete/107141/spam Del: non-english -- https://master.php.net/note/delete/107141/non-english Del: in docs -- https://master.php.net/note/delete/107141/in+docs Del: other reasons-- https://master.php.net/note/delete/107141 Reject -- https://master.php.net/note/reject/107141 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185521) next »