Sara Golemon wrote:
> Anything written in PHP could be written in C, the question you need
> to answer isn't "How?", it's "Why?".

Sure.

In general, I just thinking about how it can be useful to iterate over
values on a library itself.
Laravel, for instance, have method Collection::where(), but it
currently doesn't accepts an operator, although it should be very
useful.

It could be implemented like it:

function where($index, $value, $operator = '==') {
    return array_filter($this->array, function ($arrayValue,
$arrayIndex) use ($index, $value, $operator) {
        return compare($arrayValue[$index], $value, $operator);
    });
}

$collection->where('id', 1, '>');

Currently it could be done by using "filter" and writing an
user-defined function with > usage.
But the problem is when this condition is client-defined, not
developer-defined. For instance:

<select name="compare"> lower, greater, lower-equal, greater-equal,
equal </select>

In this case, I should implements a switch, where a compare() should works fine.

-- 
David Rodrigues

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

Reply via email to