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'));
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.14
Array ( [0] => Array ( [name] => lorem ipsum [category] => hi [quantity] => 2 [price] => 55 [id] => 1756378 [shelf] => 30 [slot] => 173 ) )

preferences:
113.63 ms | 407 KiB | 5 Q