### Discussed in https://github.com/orgs/Programming-Language-Practice/discussions/66 <div type='discussions-op-text'> <sup>Originally posted by **JoisFe** March 5, 2023</sup> # 72. include와 require를 한 번만 호출하기 ## include_once와 require_once - include 또는 require를 사용해서 다른 파일을 여러 회 불러오면 명령문을 필요한만큼 사용하면 됨 - 하지만 어떠한 경우에 의해서 여러 회 사용했지만 한 번 불러오고 그 이후에는 불러오지 않게 하려면 include_once 또는 require_once 사용 - 1회 불러온 후 그 이후에는 해당 명령문이 다시 사용되어도 불러오지 않음 ### include를 2회 사용한 예시 <img width="225" alt="image" src="https://user-images.githubusercontent.com/90208100/222967639-05c39295-3aba-49d0-894c-9abecacc4acf.png"> - a.php ``` php <?php echo "hi"; ?> ``` - b.php ``` php <?php include "./a.php"; include "./a.php"; ?> ``` - b.php 결과 <img width="36" alt="image" src="https://user-images.githubusercontent.com/90208100/222967714-490d8a9d-96ba-4b26-bc0f-c002d150565b.png"> ### include_once를 사용한 예시 <img width="218" alt="image" src="https://user-images.githubusercontent.com/90208100/222967811-ec4d8187-dbc0-422b-8795-f64f3afe6014.png"> - a.php ``` php <?php echo "hi"; ?> ``` - b.php ``` php <?php include "./a.php"; include_once "./a.php"; ?> ``` - b.php의 결과 <img width="31" alt="image" src="https://user-images.githubusercontent.com/90208100/222967876-bbbdd78f-235d-4269-a3e8-271c00f6654d.png"> - include를 사용해 a.php 파일을 불러옴 - include_once를 사용하여 a.php 파일을 불러오게 했지만 이전에 이미 한번 불러왔기 때문에 불러오지 않음 ## Reference ### 초보자를 위한 PHP 200제, 정보문화사, [김태영]</div>
Discussed in https://github.com/orgs/Programming-Language-Practice/discussions/66
Originally posted by JoisFe March 5, 2023
72. include와 require를 한 번만 호출하기
include_once와 require_once
include를 2회 사용한 예시
include_once를 사용한 예시
Reference
초보자를 위한 PHP 200제, 정보문화사, [김태영]