Skip to content

70. 하나의 파일을 여러 곳에서 사용하기 include #62

@JoisFe

Description

@JoisFe

Discussed in https://github.com/orgs/Programming-Language-Practice/discussions/61

Originally posted by JoisFe March 1, 2023

70. 하나의 파일을 여러 곳에서 사용하기 include

  • 한 번 작성한 코드를 다른 곳에서도 사용해야하는 경우가 많음
  • 만약 해당 코드를 계속 똑같이 작성한다면 효율이 좋지 않음

해결 방법 -> include 이용

include

include 사용 방법

include "파일 경로와 파일명";

image
  • a.php
<?php
    echo "hi";
?>
image
  • 다른 파일에서 include 통한 결과를 확인해보면
  • b.php
<?php
    include "./a.php";
?>
image
  • include 를 사용하니 a.php 파일을 잘 불러오는 것을 확인할 수 있다.

결론

공통적인 기능을 하는 파일을 하나 만들어서 include를 사용해 여러 곳에서 불러올 수 있음

Reference

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    200 Solved초보자를 위한 200제 책 학습을 위한 라벨입니다.PHPPHP 관련 라벨입니다.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions