/ Published in: PHP

A recursive function to permute the items of an array. The function returns an array that contains many arrays, where each array is a permutation of the original array. This process can get intensive depending on how many items are in the initial array and how big the array items are.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function permute(&$arr) { // permute the items in an array (n items, n at a time) $usedItems[] = $item[0]; $perms[] = $usedItems; // add the result to our results container } permute($arr); } return $perms; // $perms contains arrays, each a permutation of the original array. }
Comments
