Re: Method compare()

From: Date: Tue, 09 Aug 2016 18:38:08 +0000
Subject: Re: Method compare()
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-94975@lists.php.net to get a copy of this message
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

« previous php.internals (#94975) next »