LoginSignup
5
3

More than 3 years have passed since last update.

PHP 配列が空かどうかを判定する

Posted at

目的

  • PHPで配列が空かどうか判定する方法をメモ的にまとめる

情報

方法

  • empty()関数を用いて配列が空かどうかを判定する。empty()関数は空の場合trueを返す。
  • 「当該変数に配列が格納されており、かつ、その配列が空」であることをチェックしたいためempty()関数だけではなくis_array()関数も一緒に使用する。
  • 下記を実行すると変数$arrayには空の配列が格納されているため「Empty data」の文字列が出力される。

    <?php
    
    $array = [];
    
    if (is_array($array) && empty($array)) {
        echo 'Empty data';
    }
    

参考文献

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