filter() публичный статический Метод

Example: $array = array(1, 2, 3, 4); $result = Arrays::filter($array, function ($value) { return $value > 2; }); Result: Array ( [2] => 3 [3] => 4 )
public static filter ( array $elements, callable $function ) : array
$elements array
$function callable
Результат array
Пример #1
0
 private static function getClassMethods($class)
 {
     $methods = $class->getMethods();
     return Arrays::filter($methods, function (ReflectionMethod $method) {
         return !$method->isConstructor() && !$method->isStatic();
     });
 }
Пример #2
0
 private function getMatchingStubbedCalls($methodCall)
 {
     $matching = Arrays::filter($this->_stubbed_calls, function ($stubbed_call) use($methodCall) {
         return $stubbed_call->matches($methodCall);
     });
     return $matching;
 }
Пример #3
0
 private function _getColumnsWithoutPrimary(Dialect $dialect)
 {
     $primaryKeyName = $this->primaryKeyName;
     $columns = $dialect->columns();
     if ($primaryKeyName != 'id') {
         return Arrays::filter($columns, function (DatabaseColumn $column) use($primaryKeyName) {
             return $column->name != $primaryKeyName;
         });
     }
     return $columns;
 }
Пример #4
0
 /**
  * @test
  */
 public function shouldFilterValues()
 {
     //given
     $array = array(1, 2, 3, 4);
     //when
     $result = Arrays::filter($array, function ($value) {
         return $value > 2;
     });
     //then
     $this->assertEquals(array(2 => 3, 3 => 4), $result);
 }
Пример #5
0
 public function process()
 {
     $post = $this->post;
     $filterLogin = Arrays::filter($this->getElements(), function ($element) use($post) {
         if ($element->user_name == $post->user_auth->user_name && $element->password == $post->user_auth->password) {
             return $element;
         }
         return null;
     });
     if (!$filterLogin) {
         $response = new stdClass();
         $response->name = 'Invalid Login';
         $response->number = '10';
         $response->description = 'Login attempt failed please check the username and password';
         $this->response = $response;
     } else {
         $user = Arrays::first($filterLogin);
         $response = new stdClass();
         $response->id = $user->id;
         $this->response = $response;
     }
     return $this;
 }
Пример #6
0
 public function filter($function)
 {
     $this->_array = Arrays::filter($this->_array, $function);
     return $this;
 }
Пример #7
0
 private function _removeMessages()
 {
     if (!$this->_keepMessage && Session::has('messages')) {
         $messages = Arrays::filter(Session::get('messages'), function (Notice $notice) {
             return !$notice->requestUrlMatches();
         });
         $this->saveMessagesWithEmptyCheck($messages);
     }
 }
Пример #8
0
 /**
  * @return Parameter[]|array
  */
 public function getNoHeaderParameters()
 {
     return Arrays::filter($this->parameters, function (Parameter $parameter) {
         return !$parameter->isHeader();
     });
 }
Пример #9
0
 /**
  * Returns model object as a nicely formatted string.
  */
 public function inspect()
 {
     return get_called_class() . Objects::toString(Arrays::filter($this->_attributes, Functions::notNull()));
 }
Пример #10
0
 public static function getRoutesForController($controller)
 {
     return Arrays::filter(self::getRoutes(), function (RouteRule $route) use($controller) {
         return Strings::equalsIgnoreCase($route->getController(), $controller);
     });
 }