Created
April 3, 2018 06:37
-
-
Save pierredup/dbcd1ebfba41675e0fc8fb0d44c8bcc9 to your computer and use it in GitHub Desktop.
Lodash-PHP filter methhod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use function _\filter; | |
$users = [ | |
[ 'user' => 'barney', 'age' => 36, 'active' => true], | |
[ 'user' => 'fred', 'age' => 40, 'active' => false] | |
]; | |
filter($users, 'active'); | |
// => [[ 'user' => 'barney', 'age' => 36, 'active' => true]] | |
class User | |
{ | |
private $name; | |
private $active; | |
public function __construct(string $name, bool $active) | |
{ | |
$this->name = $name; | |
$this->active = $active; | |
} | |
public function isActive(): bool | |
{ | |
return $this->active; | |
} | |
} | |
$users = [ | |
new User('Barney', true), | |
new User('Fred', false), | |
]; | |
filter($users, 'active'); | |
/* => | |
[ | |
class User#219 (2) { | |
private $name => string(6) "Barney" | |
private $active => bool(true) | |
} | |
] | |
*. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment