Re: Variable Troubleshooting Code

From: Date: Tue, 10 Jan 2012 19:32:44 +0000
Subject: Re: Variable Troubleshooting Code
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-316243@lists.php.net to get a copy of this message
Jim Lucas wrote: [snip]
if (!isset($pmatch) || substr($key,0,strlen($pmatch)) == $pmatch) { print "$key = $value<br />"; }
[snip]
I would change the above the the following: if ( empty($pmatch) || ( strpos($key, $pmatch) === 0 ) ) { print "$key = $value<br />"; } it would be slightly faster
love the "skin the cat" game! What I like about this Jim is that the strpos() could be changed to allow a "contains" argument rather than a "begins with" argument... for example if you wanted to find all variable names containing 'foo'. Something like: if ( empty($pmatch) || (( strpos($tkey, $pmatch) === 0 ) || ( strpos($tkey, $pmatch) > 0 ))) { print "$key = $value<br />"; } t_foo foo_t t_foo_t would all be found. Thanks! Donovan -- D Brooke

« previous php.general (#316243) next »