3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_invoices() { return [ [ "id" => 1, "customer_id" => 81136, ], [ "id" => 2, "customer_id" => 81136, ], [ "id" => 3, "customer_id" => 81100, ], ]; } function get_customer_invoices($customer_id = null) { if ($customer_id) { // return result of `array_filter` from `get_customer_invoices` function return array_filter(get_invoices(), function ($item) use ($customer_id) { // array_filter's callback should return `true` or `false` return $item['customer_id'] === $customer_id; }); } else { return false; } } var_dump(get_customer_invoices(81136));

preferences:
26.33 ms | 405 KiB | 5 Q