note 57381 deleted from language.variables.predefined by mazzanet

From: Date: Sun, 02 Oct 2005 11:19:08 +0000
Subject: note 57381 deleted from language.variables.predefined by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96159@lists.php.net to get a copy of this message
Note Submitter: tracerdx at hotmail dot com ---- Follow up to "webdesign at benking dot com"'s solution: Why are you using a strpos method as a list when php comes with powerful arrays? This: $allowed_args = ',f_name,l_name,subject,msg,'; foreach(array_keys($_POST) as $k) { $temp = ",$k,"; if(strpos($allowed_args,$temp) !== false) { $$k = $_POST[$k]; } } Could easily be expressed as: $allowed_args = array('f_name', 'l_name', 'subject', 'msg'); foreach($allowed_args as $k) $$k = $_POST[$k]; Maybe arrays are slower than recursively srtpos-ing through strings? (Beats me) Note: Yes, variables == null may be created, but who the heck cares? and if that is a problem, then: foreach($allowed_args as $k) if (isset($_POST[$k])) $$k = $_POST[$k];

« previous php.notes (#96159) next »