3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $i='4N4P9N7P1N1P2N2P'; preg_match_all('/(\d+)(\w)/',$i,$m,2); print_r($m); foreach($m as $p) { if ($p[2]=='N') { $o.=str_repeat('=',$p[1]); } else { $o.=str_repeat('- ',(int)($p[1]/2)).($p%2?'-':''); } } echo($o);
based on 3ofjm
Output for 5.0.4 - 7.2.0
Array ( [0] => Array ( [0] => 4N [1] => 4 [2] => N ) [1] => Array ( [0] => 4P [1] => 4 [2] => P ) [2] => Array ( [0] => 9N [1] => 9 [2] => N ) [3] => Array ( [0] => 7P [1] => 7 [2] => P ) [4] => Array ( [0] => 1N [1] => 1 [2] => N ) [5] => Array ( [0] => 1P [1] => 1 [2] => P ) [6] => Array ( [0] => 2N [1] => 2 [2] => N ) [7] => Array ( [0] => 2P [1] => 2 [2] => P ) ) Notice: Undefined variable: o in /in/UN52a on line 8 ====- - -=========- - - -=-==- -
Output for 4.3.0 - 5.0.3
Array ( [0] => Array ( [0] => 4N [1] => 4 [2] => N ) [1] => Array ( [0] => 4P [1] => 4 [2] => P ) [2] => Array ( [0] => 9N [1] => 9 [2] => N ) [3] => Array ( [0] => 7P [1] => 7 [2] => P ) [4] => Array ( [0] => 1N [1] => 1 [2] => N ) [5] => Array ( [0] => 1P [1] => 1 [2] => P ) [6] => Array ( [0] => 2N [1] => 2 [2] => N ) [7] => Array ( [0] => 2P [1] => 2 [2] => P ) ) Notice: Undefined variable: o in /in/UN52a on line 8 ====- - -=========- - - -=-==- -