3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getParts() { return json_decode(<<<EOF [ { "name": "lorem ipsum", "category": "hi", "quantity": "2", "price": "55", "id": 1756378, "shelf": "30", "slot": "173" }, { "name": "foo bar", "category": "there", "quantity": "2", "price": "90", "id": 1181335, "shelf": "", "slot": "" } ] EOF , true); } function getPartByName($name) { $matches = []; $parts = getParts(); foreach ($parts as $part) { if (str_starts_with($part['name'], $name)) { $matches[] = $part; } } return $matches; } print_r(getPartByName('lorem'));

preferences:
67.44 ms | 406 KiB | 5 Q