PHP Array: join each sub-array together (Probability)

前端 未结 5 1578
谎友^
谎友^ 2021-01-11 18:22

I want simply to find-out better way to do this:

$array = array(
    array(\'a\', \'b\', \'c\'),
    array(\'e\', \'f\', \'g\'),
    array(\'h\', \'i\', \'j\'         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-11 18:28

    My non-recursive way:

     $c) {
            echo $array[$key][$c];
        }
        echo PHP_EOL;
    } while (incrementCounter($counterArray, $upperBounds));
    
    function incrementCounter(&$counterArray, $upperBounds)
    {
        if (count($counterArray) == 0 || count($counterArray) != count($upperBounds)) {
            return false;
        }
        $counterArray[0]++;
        foreach ($counterArray as $key => $value) {
            if ($counterArray[$key] >= $upperBounds[$key]) {
                $counterArray[$key] = 0;
                if (isset($counterArray[$key+1])) {
                    $counterArray[$key+1]++;
                }
                else {
                    $counterArray[$key+1] = 1;
                    return false;
                }
            }
            else {
                break;
            }
        }
        return true;
    }
    

提交回复
热议问题