두 변수는 명시적으로 반환할 수 없으며 목록/배열 데이터 구조에 넣어 반환할 수 있습니다.
예시
function factors( $n ) {
// An empty array is declared
$fact = array();
// Loop through it
for ( $i = 1; $i < $n; $i++) {
// Check if i is the factor of
// n, push into array
if( $n % $i == 0 )
array_push( $fact, $i );
}
// Return array
return $fact;
}
// Declare a variable and initialize it
$num = 12;
// Function call
$nFactors = factors($num);
// Display the result
echo 'Factors of ' . $num . ' are: <br>';
foreach( $nFactors as $x ) {
echo $x . "<br>";
} 출력
이것은 다음과 같은 출력을 생성합니다 -
Factors of 12 are: 1 2 3 4 6