LoginSignup
5
3

More than 3 years have passed since last update.

HTML構文の中に差し込むPHPの条件分岐

Last updated at Posted at 2019-06-23

はじめに

PHPを触ってみて2週間
ログイン機能を実装していたのだが、
ユーザー毎に機能を分けるのがうまくいかない!
条件分岐の書き方がわからない!!

わかったこと

・PHPの条件分岐でわかりやすかったのは2つ

メモ

環境

  • PHP7.3.6

やりたかったこと

タスク管理アプリでユーザー毎に権限を与える。
HTML構文の中に差し込みたい

管理ユーザー:ユーザー登録・ユーザー一覧・todo登録・todo一覧
一般ユーザー:todo登録・todo一覧

解決

1つ目 綺麗に区切られていて把握しやすい

    <?php if ($sample == '○○○') : ?>
   if文が通った時のHTMLコード
  <?php else: ?>
   elseの時に実行されたいHTMLコード
  <?php endif; ?>

2つ目 一般的な書き方?

 <?php
  if ($sample == '○○○') {
    print 'if文が通った時のHTMLコード';
  } else ($sample == '○○○') {
    print 'elseの時に実行されたいHTMLコード';
  } 
 ?>

参考サイト

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3