On Sat, Dec 6, 2008 at 22:52, Lars Strojny <[EMAIL PROTECTED]> wrote:
> Alright, than I would appreciate a few real world use cases.

Ok one immediate use case I can think of:

http://pear.php.net/package/Numbers_Words

In brazilian portuguese we write numbers like that:

1023 => mil e vinte e tres
123 => cento e vinte e tres
23 => vinte e tres
20 => vinte

So we can have an array that binds '3' to 'tres', '2' as a dozen to
'vinte', zero to false or empty string, etc. Parse the numbers from
left to right adding each word as an array element. In the end we can
just implode everything using the delimiter ' e '. Using actual
implode for the number 1023 would result as 'mil e e vinte e tres'
instead of just 'mil e vinte e tres'.

Using array_filter before every implode() would add a big visual
overhead. I don't want to get into deeper details but translating
numbers to pt_br words is a lot more complex. We actually have to
parse, evaluate and implode() every "chunk" of three numbers first,
then add all the chunks to a new array and finally implode()
everything together because there are different rules for inter-chunks
"relationship" and intra-chunks relationship.

I am not saying the use of array_filter *is* a bottleneck. But I am
sure there are a *lot* of heavy applications out there that runs a lot
happier with any bit of performance gain. Also less code means happier
programmers. Example:

function myfunc($var) {
// logic to test if var is not null, not false, not empty string etc.
}

// NOTE: leaving the callback function empty is not desired. 0 and 0.0
should not be skipped in the implode array !
array_filter($arr, 'myfunc');
implode('foo', $arr);

against:

implode('foo', $arr, true);

Again this is just one single example. I had to deal with this
situation a *lot* of times before.

> I guess you meant "Absolutely not" ;-)

Absolutely (now I think its used correctly...)

> The procedure: register a wiki account and start using the "template"
> from the traits proposal. We are pretty liberal with adding/removing
> chapters, so adjust it as much as you need it to make your point clear.

Right.

Best Regards,
Igor Feghali.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to