NYCPHP Meetup

NYPHP.org

[nycphp-talk] Named parameters

Emmanuel. M. Decarie emm at scriptdigital.com
Sat May 10 14:33:49 EDT 2003


Thanks Adam and Brent,

The pointer to extract is a good one. And Adam, I feel a shame that I 
didn't check the Recipe 6.4 in the PHP Cookbook, especially when your 
book sit on my desk all day long. (for the others that don't  have 
the book, you can6 download the recipies here: 
<http://examples.oreilly.com/phpckbk/>)

I came up with my own version combining extract () and the spirit of 
Adam's recipe (clearly identified parameters).

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

     extract ($argsDefault, EXTR_PREFIX_ALL, 'arg');
     extract ($args, EXTR_PREFIX_ALL, 'arg');

     $item = "";
     $item .= "<title>$arg_title</title>\
";
     $item .= "<link>$arg_link</link>\
";
     $item .= "<description>$arg_description</description>\
";
     $item .= "<category>$arg_category</category>\
";

     return $item;

}

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

$rssItem = formatItem ( $rssItem );
echo $rssItem;

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


Look nice?

Cheers
-Emmanuel


-- 
______________________________________________________________________
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