$users = [ ['name' => 'John', 'age' => 25], ['name' => 'Sarah', 'age' => 30], ['name' => 'Peter', 'age' => 20] ]; $firstJohn = findFirst($users, function($user) { return $user['name'] === "John"; }); print_r($firstJohn); // ['name' => 'John', 'age' => 25]
use Illuminate\Database\Eloquent\Model; class User extends Model { protected $table = 'users'; } $firstAdult = User::where('age', '>', 18)->first();In the first example, we used a custom function as the callback to find the first element that satisfies the condition. In the second example, we used the `first` method of the Laravel ORM to retrieve the first record in the database that meets the condition. It is not clear from the given examples which package or library is being used, but the second example suggests the use of Laravel.