3v4l.org

run code in 300+ PHP versions simultaneously
<?php $attribute_options_string = "Spice (Very Hot/3, Hot/2, Medium/1) | Size(Small,Medium,Large)"; $attribute_options_array = array(); $attributes = preg_split('/\s*\|\s*/', $attribute_options_string); foreach ($attributes as $attribute) { preg_match('/\s*(\w+)\s*\(([^)]+)/', $attribute, $matches); $attribute_name = strtolower($matches[1]); $options = preg_split('/\s*,\s*/', $matches[2]); foreach ($options as $option) { if (strpos($option, '/') !== false) { list($option_name, $option_value) = preg_split('#\s*/\s*#', $option); $attribute_options_array[$attribute_name][strtolower($option_name)] = $option_value; } else { $attribute_options_array[$attribute_name][] = strtolower($option); } } } var_export($attribute_options_array);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'spice' => array ( 'very hot' => '3', 'hot' => '2', 'medium' => '1', ), 'size' => array ( 0 => 'small', 1 => 'medium', 2 => 'large', ), )

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:
122.25 ms | 405 KiB | 5 Q