Re: Is this a missing feature?

From: Date: Mon, 05 Feb 2001 00:33:23 +0000
Subject: Re: Is this a missing feature?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-38165@lists.php.net to get a copy of this message
I should check my version then... =O) lux Christian Reiniger wrote:
On Monday 05 February 2001 00:51, Lux wrote:
But the feature is useless :)
    function a ($hash, $text = "") {
       $attr_text = "";
       while (list ($k, $v) = each ($hash)) {
          $attr_text .= " $k=\"$v\"";
       }
       return "<a$attr_text>$text</a>";
    }
    // what also doesn't work
    // echo a (array("href" => "http://www.google.com/", "target" =>
"_blank"), "Visit Google!");
Works fine for me, sorry (php 4.0.4)
    // another example
    echo a ($attrs = array ("href" => "http://www.google.com/"),
         img ($attrs = array (
             "src" =>
"http://www.google.com/images/title_homepage4.gif", "alt" => "Visit
Google!",
             "border" => "0")
         )
    );
works, rewritten to echo a (array ("href" => "http://www.google.com/"), img (array (
		    "src" => "http://www.google.com/images/title_homepage4.gif",
		    "alt" => "Visit Google!",
		    "border" => "0")
	    )
       );
    /* now ideally, this could be written much more cleanly, perhaps...
    echo a(['href' => [http://www.google.com/'],
         img(['src' =>
'http://www.google.com/images/title_homepage4.gif', 'alt' => 'Visit
Google!', 'border' => '0'])
    );
    */
So it basically boils down to "array (a => b)" versus "[a => b]" And I personally feel the array () notation is at least as nice as the [] one. Well, it's a matter of taste. But it certainly isn't harder to read, not detrimental on cleanness and elegance of the code.
-- John Luxford Simian Systems w: www.simian.ca e: lux@simian.ca p: 204.946.5955 --

« previous php.general (#38165) next »