empty() 빈 값인지 아닌지를 체크 - 비어있으면 true 비어있지 않으면 false 반환
isset() 존재하는지 아닌지를 체크 - 존재한다면 true 존재하지 않는다면 false 반환
ex08_empty_isset.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
$testStr = 0; // int
$testStr2 = 100; // int
$testStr3 = "0"; // str
$testStr4 = "100"; // str
$testStr5 = "abcd"; // str
$testStr6 = ""; // str
$testStr7 = null; // null
$testStr8 = true; // bool
$testStr9 = false; // bool
// 1. int 0
echo empty($testStr) ? "int 0 empty는 Y <br/>" : "int 0 empty는 N <br/>"; // Y
echo isset($testStr) ? "int 0 isset은 Y <br/>" : "int 0 isset은 N <br/>"; // Y
// 2. int 0 외의 숫자
echo empty($testStr2) ? "int 100 empty는 Y <br/>" : "int 100 empty는 N <br/>"; // N
echo isset($testStr2) ? "int 100 isset은 Y <br/>" : "int 100 isset은 N <br/>"; // Y
// 3. str "0"
echo empty($testStr3) ? "str 0 empty는 Y <br/>" : "str 0 empty는 N <br/>"; // Y
echo isset($testStr3) ? "str 0 isset은 Y <br/>" : "str 0 isset은 N <br/>"; // Y
// 4. str "100"
echo empty($testStr4) ? "str 100 empty는 Y <br/>" : "str 100 empty는 N <br/>"; // N
echo isset($testStr4) ? "str 100 isset은 Y <br/>" : "str 100 isset은 N <br/>"; // Y
// 5. str "abcd"
echo empty($testStr5) ? "str abcd empty는 Y <br/>" : "str abcd empty는 N <br/>"; // N
echo isset($testStr5) ? "str abcd isset은 Y <br/>" : "str abcd isset은 N <br/>"; // Y
// 6. str ""
echo empty($testStr6) ? "str empty는 Y <br/>" : "str empty는 N <br/>"; // Y
echo isset($testStr6) ? "str isset은 Y <br/>" : "str isset은 N <br/>"; // Y
// 7. null
echo empty($testStr7) ? "null empty는 Y <br/>" : "null empty는 N <br/>"; // Y
echo isset($testStr7) ? "null abcd isset은 Y <br/>" : "null isset은 N <br/>"; // N
// 8. true
echo empty($testStr8) ? "true empty는 Y <br/>" : "true empty는 N <br/>"; // N
echo isset($testStr8) ? "true isset은 Y <br/>" : "true isset은 N <br/>"; // Y
// 9. false
echo empty($testStr9) ? "false empty는 Y <br/>" : "false empty는 N <br/>"; // Y
echo isset($testStr9) ? "false isset은 Y <br/>" : "false isset은 N <br/>"; // Y
?>
</body>
</html>
include
다른 PHP 파일을 코드 안으로 불러와서 사용
include "파일경로"
index.php
<?php
include "header.php";
?>
<section>
메인페이지
</section>
<?php
include "footer.php";
?>
header.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="wrap">
<header>
<h1><a href="index.php">green</a></h1>
<nav>
<ul>
<li><a href="sub.php">menu1</a></li>
<li><a href="#">menu2</a></li>
<li><a href="#">menu3</a></li>
<li><a href="#">menu4</a></li>
</ul>
</nav>
</header>
footer.php
<footer>
푸터입니다.
</footer>
</div>
</body>
</html>
sub.php
<?php
include 'header.php';
?>
<section>
서브페이지입니다.
</section>
<?php
include 'footer.php';
?>
'Stack > PHP' 카테고리의 다른 글
[PHP] MySQL 연동하기 (0) | 2022.05.26 |
---|---|
[PHP] file 관련 함수를 이용한 Blog (0) | 2022.05.26 |
[PHP] file (0) | 2022.05.25 |
[PHP] get / post 전송 방식 (0) | 2022.05.25 |
[PHP] 제어문 (0) | 2022.05.25 |