3v4l.org

run code in 500+ PHP versions simultaneously
<?php $products = array( array( 'product_name' => 'My First Product', 'price' => 50, 'sizes' => [ 'S', 'L', 'XL' ] ), array( 'product_name' => 'My Second Product', 'price' => 45, 'sizes' => [ 'S', 'M', 'L', 'XL' ] ) ); $productNames = array(); foreach ($products as $product) { if (in_array('M', $product['sizes'])) $productNames[] = $product['product_name']; } print_r($productNames);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.32, 8.3.0 - 8.3.32, 8.4.1 - 8.4.24, 8.5.0 - 8.5.9
Array ( [0] => My Second Product )

preferences:
72.51 ms | 1155 KiB | 4 Q