3v4l.org

run code in 300+ PHP versions simultaneously
<?php function svg_icon(array $atts = []): ?string { // Get the provided values or a default value $icon = $atts['icon'] ?? false; $label = $atts['label'] ?? false; // This is required, so if it not set bail if (!$icon) { return null; } // These are our possible SVGs static $config = [ 'arrow' => '<svg aria-hidden="true" role="img" focusable="false" width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd"><path d="M21.883 12l-7.527 6.235.644.765 9-7.521-9-7.479-.645.764 7.529 6.236h-21.884v1h21.883z"/></svg>', 'hamburger' => '<svg aria-hidden="true" role="img" focusable="false" clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="m13 16.745c0-.414-.336-.75-.75-.75h-9.5c-.414 0-.75.336-.75.75s.336.75.75.75h9.5c.414 0 .75-.336.75-.75zm9-5c0-.414-.336-.75-.75-.75h-18.5c-.414 0-.75.336-.75.75s.336.75.75.75h18.5c.414 0 .75-.336.75-.75zm-4-5c0-.414-.336-.75-.75-.75h-14.5c-.414 0-.75.336-.75.75s.336.75.75.75h14.5c.414 0 .75-.336.75-.75z" fill-rule="nonzero"/></svg>', 'close' => '<svg aria-hidden="true" role="img" focusable="false" clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="m12.002 2.005c5.518 0 9.998 4.48 9.998 9.997 0 5.518-4.48 9.998-9.998 9.998-5.517 0-9.997-4.48-9.997-9.998 0-5.517 4.48-9.997 9.997-9.997zm0 1.5c-4.69 0-8.497 3.807-8.497 8.497s3.807 8.498 8.497 8.498 8.498-3.808 8.498-8.498-3.808-8.497-8.498-8.497zm0 7.425 2.717-2.718c.146-.146.339-.219.531-.219.404 0 .75.325.75.75 0 .193-.073.384-.219.531l-2.717 2.717 2.727 2.728c.147.147.22.339.22.531 0 .427-.349.75-.75.75-.192 0-.384-.073-.53-.219l-2.729-2.728-2.728 2.728c-.146.146-.338.219-.53.219-.401 0-.751-.323-.751-.75 0-.192.073-.384.22-.531l2.728-2.728-2.722-2.722c-.146-.147-.219-.338-.219-.531 0-.425.346-.749.75-.749.192 0 .385.073.531.219z" fill-rule="nonzero"/></svg>', ]; // If the requested icon doesn't exist, bail if (!$svg = $config[$icon] ?? null) { return null; } // If we have a label, un-hide the SVG and set the ARIA attribute if (!empty($label)) { $svg = str_replace('<svg ', '<svg aria-label="'.esc_attr($label).'"', $svg); $svg = str_replace('aria-hidden="true"', '', $svg); } return $svg; } // Samples echo svg_icon(['icon' => 'hamburger', 'label' => 'Main Menu']); echo PHP_EOL; echo svg_icon(['icon' => 'arrow', 'label' => 'Click me']); echo PHP_EOL; echo svg_icon(['icon' => 'close']); echo PHP_EOL; echo svg_icon(['icon' => 'nope']); echo PHP_EOL; // !! DO NOT COPY THIS FUNCTION !! // This is a stub-function ONLY for the 3v4l.org site. function esc_attr($string){return $string;}

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.120.0090.00924.17
8.4.110.0110.01021.44
8.4.100.0050.00618.98
8.4.90.0110.00918.71
8.4.80.0040.00517.71
8.4.70.0110.00817.89
8.4.60.0130.00920.48
8.4.50.0110.00917.75
8.4.40.0030.01320.46
8.4.30.0130.00622.23
8.4.20.0080.00019.59
8.4.10.0000.00822.05
8.3.250.0090.00918.91
8.3.240.0060.00317.16
8.3.230.0120.00616.61
8.3.220.0110.00717.22
8.3.210.0100.00721.16
8.3.200.0030.00616.55
8.3.190.0150.00516.46
8.3.180.0130.00616.58
8.3.170.0040.01118.97
8.3.160.0090.00916.69
8.3.150.0060.00920.95
8.3.140.0000.00816.54
8.3.130.0040.00418.61
8.3.120.0030.00719.07
8.3.110.0000.00920.94
8.3.100.0030.00624.06
8.3.90.0030.00626.77
8.3.80.0030.00616.63
8.3.70.0090.00618.31
8.3.60.0060.00916.88
8.3.50.0160.00616.89
8.3.40.0070.00720.29
8.3.30.0060.00918.81
8.3.20.0070.00024.18
8.3.10.0040.00424.66
8.3.00.0080.00026.16
8.2.290.0100.00820.68
8.2.280.0060.00620.08
8.2.270.0120.00617.41
8.2.260.0050.00320.70
8.2.250.0070.00318.47
8.2.240.0040.00418.92
8.2.230.0130.00922.58
8.2.220.0060.00337.54
8.2.210.0080.00026.77
8.2.200.0070.00416.63
8.2.190.0110.00418.16
8.2.180.0140.00716.75
8.2.170.0110.00419.08
8.2.160.0090.00622.96
8.2.150.0000.00825.66
8.2.140.0080.00024.66
8.2.130.0070.00026.16
8.2.120.0040.00421.18
8.2.110.0110.00020.52
8.2.100.0000.00920.39
8.2.60.0100.00517.44
8.1.330.0160.00721.91
8.1.320.0110.00816.27
8.1.310.0160.00316.81
8.1.300.0050.00316.07
8.1.290.0060.01230.84
8.1.280.0160.00625.92
8.1.270.0070.00724.66
8.1.260.0030.00626.35
8.1.250.0040.00428.09
8.1.240.0060.00320.70
8.1.230.0060.00318.49

preferences:
28.57 ms | 403 KiB | 5 Q