Re: default/optional parameters in function

From: Date: Thu, 04 Jul 2002 01:43:33 +0000
Subject: Re: default/optional parameters in function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-105338@lists.php.net to get a copy of this message
On Wed, Jul 03, 2002 at 05:44:28PM -0800, Chris Lott wrote: > > I have a function that writes meta tags... if a tag (or tags) is not > specified, then it gets a default value... is there a cleaner way to > do this? Not that I can think of. I do have some thoughts, though... > if ($type["description"]) { if ( !empty($type['description']) ) { Would be a better way to do this check, because that key may not be set and if your error reporting level ever gets elevated, you'll be getting lots of warnings. > if ($type["keywords"]) { > print '<meta name="keywords" content="' . > $type["keywords"] . '" > />'; > } > else { > print '<meta name="keywords" content="generic keyword list" > />'; > } I'd also tweak the process a bit to have just the different parts in the if statement: print '<meta name="keywords" content="'; if ( empty($type['keywords']) ) { echo 'generic keyword list'; } else { echo $type['keywords']; } echo '" />'; Note use of single quotes around the array key names, as well. Enjoy, --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

« previous php.general (#105338) next »