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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
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.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 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.
Output for 7.0.0 - 7.0.25, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Warning: Creating default object from empty value in /in/kd6Hk on line 79 Warning: Illegal string offset 'URL' in /in/kd6Hk on line 81 Fatal error: Uncaught Error: Call to undefined function dd() in /in/kd6Hk:83 Stack trace: #0 {main} thrown in /in/kd6Hk on line 83
Process exited with code 255.

preferences:
165.08 ms | 403 KiB | 180 Q