Get all subsets of array

If you have a list of items (for example):

$arr = array(
 1 => null,
 2 => 1,
 3 => 2,
 4 => 3,
 5 => 3);

And you need all subsets of item index 1

1 -> 2, 3, 4, 5
2 -> 3, 4, 5
3 -> 4, 5
4 -> 
5 ->

 Our desired function:

function allSubsets($arr) {
    $result = array();
 
    foreach ($arr as $key => $value) {
        if ($value) {
            $result[$value][] = $key;
            $tmpResult = $result;
            foreach ($tmpResult as $index => $list) {
                if ($index >= $key) {
                    break;
                }
 
                foreach ($list as $i => $j) {
                    if ($value == $j) {
                        $result[$index][] = $key;
                    }
                }
            }
        }
    }
 
    return $result;
}

Example: 

$arr = array(
    1 => null,
    2 => 1,
    3 => 2,
    4 => 3,
    5 => 3);
 
print_r(allSubsets($arr));

Result:

Array
(
    [1] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 4
            [3] => 5
        )

    [2] => Array
        (
            [0] => 3
            [1] => 4
            [2] => 5
        )

    [3] => Array
        (
            [0] => 4
            [1] => 5
        )
)

Recommended pages

Create directory function...

Create directory if not exists. function createDir( $dir ) { if ( !is_dir( $dir ) ) { mkdir( $dir, 0777 ); return true; } return false; }...

PHP subwords() Function...

Function subwords, gets words by max num....

Email Address Checker...

This function check if an e-mail address is valid or not. function valid_email($email) { return preg_match('/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/', $email);...

Human readable file size...

This function return formatting of file sizes in a human readable format. function formatFileSize( $size ) { $file_size = $size; $i = 0;   $name = array( 'byte', 'kB', 'MB', '...