3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function pc_permute($items, $perms = array()) { if (empty($items)) { echo join(' ', $perms) . "<br />"; } else { for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $newperms = $perms; list($foo) = array_splice($newitems, $i, 1); array_unshift($newperms, $foo); pc_permute($newitems, $newperms); } } } $arr = array('peter', 'paul', 'mary'); pc_permute($arr); ?>
Output for 4.3.0 - 7.1.10
peter paul mary<br />paul peter mary<br />peter mary paul<br />mary peter paul<br />paul mary peter<br />mary paul peter<br />