Help us understand the problem. What is going on with this article?

空文字をexplode()で分割した時の返り値

PHPで explode() 使う時に第2引数に空文字入ってるとどうなるんだ?と思い調べてみましたが、
マニュアルの該当箇所分かりづらかったので、残しておきます。結構初心者向けです。

サンプルコード

下記コードで返り値を確かめます。

$str = "";
$res = explode(",", $str);
print_r($res);

( PHPマニュアル より引用 )

返り値

結果は以下の通りです。

array(1) {
    [0] => 
    string(0) ""
}

keyとして0を、valueとして空の文字列を持つ1要素の配列が返されます。

え、なんで1要素いれた!? 空配列でいいじゃん!!

ちなみに私は、この後 $resempty() で判定しようとして失敗しましたw

参考

PHPマニュアル:http://php.net/manual/ja/function.explode.php#99830

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away