7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Last updated at Posted at 2021-01-19

目的

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

情報

方法

  • empty()関数を用いて配列が空かどうかを判定する。empty()関数は空の場合trueを返す。

  • 「当該変数に配列が格納されており、かつ、その配列が空」であることをチェックしたいためempty()関数だけではなくis_array()関数も一緒に使用する。

  • 下記を実行すると変数$arrayには空の配列が格納されているため「Empty data」の文字列が出力される。

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

参考文献

7
5
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
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?