> But the feature is useless :)
Here, I removed the reference, so we can stop fussing over it (it wasn't the
question to begin with), and here's an example of a potential use for this
(a stupid example, but still...). I'm not weighing out the benefits of
references, I'm striving to achieve the cleanest and most elegant code I
can, because the larger the project, the more code you have to read, and
the uglier it can get.
That's where a language like Ruby excels. There's less syntactical crap,
it's very easy to read, and it's caused me to consider switching to eRuby
(like mod_perl, allows <% ruby this, ruby that %> in your html) because it
is structurally easier and more geared towards larger projects.
(that last statement will probably get me murdered on a PHP list)
But honestly, the only problem is finding a host running eRuby that I don't
have to maintain myself. I'm lazy, after all.
later,
lux
<?php
function a ($hash, $text = "") {
$attr_text = "";
while (list ($k, $v) = each ($hash)) {
$attr_text .= " $k=\"$v\"";
}
return "<a$attr_text>$text</a>";
}
function img ($hash) {
$attr_text = "";
while (list ($k, $v) = each ($hash)) {
$attr_text .= " $k=\"$v\"";
}
return "<img$attr_text />";
}
// works this way
$attrs = array (
"href" => "http://www.google.com/",
"target" => "_blank"
);
echo a ($attrs, "Visit Google!");
echo "\n\n";
// also this way (thanx teodor!)
echo a ($attrs = array (
"href" => "http://www.google.com/",
"target" => "_blank"
), "Visit Google!");
// ideally, i'd like to say this though...
// echo a (["href" => "http://www.google.com/", "target" =>
"_blank"], "Visit Google!");
// what also doesn't work
// echo a (array("href" => "http://www.google.com/", "target" =>
"_blank"), "Visit Google!");
echo "\n\n";
// 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")
)
);
/* 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'])
);
*/
?>
--
John Luxford
Simian Systems
w: www.simian.ca
e: [EMAIL PROTECTED]
p: 204.946.5955
--
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]