PHP Source (ch08/exam08-12.php)
단계: 0 / 0
1-7<!DOCTYPE html> <html> ... <body>
8<?php
9function swap(&$a, &$b) { // 참조(Reference)로 수신
10$tmp = $a;
11$a = $b;
12$b = $tmp;
13}
15$num1 = 10;
16$num2 = 20;
17echo "swap(&$a, &$b) 실행 전 : $num1 = $num1, $num2 = $num2<br>";
19swap($num1, $num2);
20echo "swap(&$a, &$b) 실행 후 : $num1 = $num1, $num2 = $num2<br>";
21?>
22-23</body> </html>
참조 포인터 메모리 구조 (&)
실제 메모리 셀 (Shared Storage)
[메모리 #01] $num1 & $a
10
10
[메모리 #02] $num2 & $b
20
20
$tmp 임시 저장값: -
&$a → $num1, &$b → $num2 연결