NYCPHP Meetup

NYPHP.org

[nycphp-talk] Named parameters

Emmanuel. M. Decarie emm at scriptdigital.com
Sat May 10 15:02:32 EDT 2003


A cleaner way might be to use array_merge instead of extract because 
you can more easily return an arrray.

function sanitize ( $args ) {
   $argsDefault = array (
           'title' => date ('r'),
           'link' => "http://blog.scriptdigital.com",
           'description' => "Whatever...",
           'category' =>  "Out of the box");

     $args = array_merge ($argsDefault, $args);
     return $args;
}

$item = array (
       'link' => "http://apple.com",
       'description' => "Apple web site.");

$cleanItem = sanitize ( $item );

$xmlItem = "";
foreach ($cleanItem as $xmltag => $val) {
   $xmlItem .= "<$xmltag>$val</$xmltag>\
";
}

echo $xmlItem;

-->
<title>Sat, 10 May 2003 15:02:39 -0400</title>
<link>http://apple.com</link>
<description>Apple web site.</description>
<category>Out of the box</category>


-- 
______________________________________________________________________
Emmanuel Décarie / Programmation pour le Web - Programming for the Web
Radio UserLand/Frontier - Perl - PHP - Javascript  <http://scriptdigital.com/>
Blog: <http://blog.scriptdigital.com> - AIM: scriptdigital




More information about the talk mailing list