backTrack($candidates, $target, 0, []); return $this->result; } function backTrack($candidates, $left, $step, $path) { if($left === 0){ $this->result[] = $path; return; } if($step === count($candidates)){ return; } for ($i = 0; $i <= intval($left / $candidates[$step]); $i++){ for ($j = 0; $j < $i; $j++){ $path[] = $candidates[$step]; } $this->backTrack($candidates, $left - $i * $candidates[$step], $step + 1, $path); for ($j = 0; $j < $i; $j++){ array_pop($path); } } } }