Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

72. include와 require를 한 번만 호출하기 #67

Open
JoisFe opened this issue Mar 5, 2023 Discussed in #66 · 0 comments
Open

72. include와 require를 한 번만 호출하기 #67

JoisFe opened this issue Mar 5, 2023 Discussed in #66 · 0 comments
Labels
200 Solved 초보자를 위한 200제 책 학습을 위한 라벨입니다. PHP PHP 관련 라벨입니다.

Comments

@JoisFe
Copy link
Member

JoisFe commented Mar 5, 2023

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 또는 require를 사용해서 다른 파일을 여러 회 불러오면 명령문을 필요한만큼 사용하면 됨
  • 하지만 어떠한 경우에 의해서 여러 회 사용했지만 한 번 불러오고 그 이후에는 불러오지 않게 하려면 include_once 또는 require_once 사용
  • 1회 불러온 후 그 이후에는 해당 명령문이 다시 사용되어도 불러오지 않음

include를 2회 사용한 예시

image
  • a.php
<?php
  echo "hi";
?>
  • b.php
<?php
    include "./a.php";
    include "./a.php";
?>
  • b.php 결과
image

include_once를 사용한 예시

image
  • a.php
<?php
  echo "hi";
?>
  • b.php
<?php
    include "./a.php";
    include_once "./a.php";
?>
  • b.php의 결과
image
  • include를 사용해 a.php 파일을 불러옴
  • include_once를 사용하여 a.php 파일을 불러오게 했지만 이전에 이미 한번 불러왔기 때문에 불러오지 않음

Reference

초보자를 위한 PHP 200제, 정보문화사, [김태영]

@JoisFe JoisFe added 200 Solved 초보자를 위한 200제 책 학습을 위한 라벨입니다. PHP PHP 관련 라벨입니다. labels Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
200 Solved 초보자를 위한 200제 책 학습을 위한 라벨입니다. PHP PHP 관련 라벨입니다.
Projects
None yet
Development

No branches or pull requests

1 participant