3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $a = array("#000000","#FFFFFF","#642424","#CC0605","#CB2821","#A2231D","#AF2B1E","#BF4435","#F54021","#C93C20","#FFDDD6","#F44611","#F75E25","#C1876B","#FABFA1","#734222","#FF7514","#FFCC99","#8A6642","#FDF4E3","#F3A505","#C6A664","#F4A900","#C2B078","#F5CB21","#E6D690","#FAD201","#E1CC4F","#F3DA0B","#7E7B52","#FFFCC1","#B8B799","#F8F32B","#FFFF99","#EDFF21","#B8CE3B","#424632","#343B29","#85BD3E","#31372B","#79BB51","#89AC76","#4FAE2E","#C0DEBC","#2D572C","#8D948D","#1CA744","#1E5945","#39B49F","#3F888F","#439AA4","#256D7B","#434B4D","#293133","#008FB7","#0D3A4D","#D0E6F1","#474B4E","#2271B3","#0E294B","#0B2C59","#0E3987","#4170CC","#1D1E33","#A49FC7","#6C3EC3","#261448","#986DE9","#37225D","#260B3E","#D8C6DE","#6C4675","#FFA3FF","#E54EE5","#6D3F5B","#D569A7","#A03472","#9E1A65","#421C31","#CF3476","#DE4C8A","#4A192C","#641C34","#F8C5CE","#EA899A","#412227","#5E2129","#9B111E","#75151E","#D60B11","#D36E70","#D53032" );   function cf_sort_hex_colors($colors) { $map = array( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'a' => 10, 'b' => 11, 'c' => 12, 'd' => 13, 'e' => 14, 'f' => 15, ); $c = 0; $sorted = array(); foreach ($colors as $color) { $color = strtolower(str_replace('#', '', $color)); if (strlen($color) == 6) { $condensed = ''; $i = 0; foreach (preg_split('//', $color, -1, PREG_SPLIT_NO_EMPTY) as $char) { if ($i % 2 == 0) { $condensed .= $char; } $i++; } $color_str = $condensed; } $value = 0; foreach (preg_split('//', $color_str, -1, PREG_SPLIT_NO_EMPTY) as $char) { $value += intval($map[$char]); } $value = str_pad($value, 5, '0', STR_PAD_LEFT); $sorted['_'.$value.$c] = '#'.$color; $c++; } ksort($sorted); return $sorted;} var_dump(cf_sort_hex_colors($a));
Output for 5.4.0 - 5.4.32
Parse error: syntax error, unexpected 'function' (T_FUNCTION) in /in/H2aHj on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_FUNCTION in /in/H2aHj on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/H2aHj on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/H2aHj on line 3
Process exited with code 255.