3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array ( '@attributes' => array ( 'Category' => 'primary', ), 'SwatchImage' => array ( 'URL' => 'https://images-na.ssl-images-amazon.com/images/I/41ElcqNVGmL._SL30_.jpg', 'Height' => '20', 'Width' => '30', ), 'SmallImage' => array ( 'URL' => 'https://images-na.ssl-images-amazon.com/images/I/41ElcqNVGmL._SL75_.jpg', 'Height' => '49', 'Width' => '75', ), 'ThumbnailImage' => array ( 'URL' => 'https://images-na.ssl-images-amazon.com/images/I/41ElcqNVGmL._SL75_.jpg', 'Height' => '49', 'Width' => '75', ), 'TinyImage' => array ( 'URL' => 'https://images-na.ssl-images-amazon.com/images/I/41ElcqNVGmL._SL110_.jpg', 'Height' => '72', 'Width' => '110', ), 'MediumImage' => array ( 'URL' => 'https://images-na.ssl-images-amazon.com/images/I/41ElcqNVGmL._SL160_.jpg', 'Height' => '104', 'Width' => '160', ), 'LargeImage' => array ( 'URL' => 'https://images-na.ssl-images-amazon.com/images/I/41ElcqNVGmL.jpg', 'Height' => '325', 'Width' => '500', ), 'HiResImage' => array ( 'URL' => 'https://images-na.ssl-images-amazon.com/images/I/81OwsmYhlcL.jpg', 'Height' => '1300', 'Width' => '2000', ), ); $sizesFor = [ 'primary' => [ 'SwatchImage', 'SmallImage', 'ThumbnailImage', 'TinyImage', 'MediumImage', 'LargeImage', 'HiResImage' ], 'variant' => [ 'MediumImage','LargeImage' ] ]; $productImages = []; foreach ($array as $key => $value) { if(isset($value['@attributes'])) { if(isset($sizesFor[$value['@attributes']['Category']])) { foreach ($sizesFor[$value['@attributes']['Category']] as $k => $type) { if (!isset($value[$type])) continue; $productImage->image_type = $value['@attributes']['Category']; $productImage->image_size = $type; $productImage->image_link = $value[$type]['URL']; $productImage->image_order = $k; $productImages[] = $productImage; } } } if($key === '@attributes') { foreach ($sizesFor['primary'] as $order => $type) { if (!isset($type)) continue; $productImage->image_type = $value; $productImage->image_size = $type; $productImage->image_link = $type['URL']; $productImage->image_order = $order; dd($productImage); $productImages[] = $productImage; } } }
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Attempt to assign property "image_type" on null in /in/kd6Hk:79 Stack trace: #0 {main} thrown in /in/kd6Hk on line 79
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
49.33 ms | 401 KiB | 8 Q