method find documentation in bbn\X

Returns the array's first index, which satisfies the 'where' condition.

Example

X::hdump(X::find([[ 'id' => 1, 'name' => 'Andrew', 'fname' => 'Williams' ], [ 'id' => 2, 'name' => 'Albert', 'fname' => 'Taylor' ], [ 'id' => 3, 'name' => 'Mike', 'fname' => 'Smith' ], [ 'id' => 4, 'name' => 'John', 'fname' => 'White' ]], ['id' => 4])); // int 3 X::hdump(X::find([[ 'id' => 1, 'name' => 'Andrew', 'fname' => 'Williams' ], [ 'id' => 2, 'name' => 'Albert', 'fname' => 'Taylor' ], [ 'id' => 3, 'name' => 'Mike', 'fname' => 'Smith' ], [ 'id' => 4, 'name' => 'John', 'fname' => 'White' ]], ['name' => 'Albert', 'fname' => 'Taylor'])); // int 1 function(array $ar, $where, int $from = 0) { if (!empty($where)) { if (is_array($where)) { $where = self::treatConditions($where); } foreach ($ar as $i => $v) { if (!$from || ($i >= $from)) { $ok = 1; if (is_callable($where)) { $ok = (bool)$where($v); } elseif (!is_array($where)) { $ok = $v === $where; } else { $v = (array)$v; $ok = self::compareConditions($v, $where); } if ($ok) { return $i; } } } } return null; }

Returns the array's first index, which satisfies the 'where' condition. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.