3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $filter = '/projects/filter/2706/seg/546/item-type/1:2/task/4467/item-type/2:1/type/or/page/1'; $params = explode('/', $filter); $params = array_slice($params, 4); $i = 0; $retval = array(); $lastval = ''; foreach($params as $param) { if ($i % 2) { $retval[$lastval] = $param; } else { $retval[$param] = FALSE; $lastval = $param; } $i++; } var_dump($retval);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(5) { ["seg"]=> string(3) "546" ["item-type"]=> string(3) "2:1" ["task"]=> string(4) "4467" ["type"]=> string(2) "or" ["page"]=> string(1) "1" }