Created
February 26, 2014 15:23
-
-
Save hirak/9231474 to your computer and use it in GitHub Desktop.
explode()の挙動がキモい ref: http://qiita.com/Hiraku/items/a58b8aac3f9e55cd1bd5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var_dump(explode(' ', '')); | |
//array("") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$arr = array(); | |
$str = implode(' ', $arr); | |
var_dump($str); //(空文字) | |
$arr = explode(' ', $str); | |
var_dump($arr); //[''] ←ちょwwww |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$arr = array(); | |
$str = implode(' ', $arr); | |
var_dump($str); //(空文字) | |
$arr = ($str==='') ? array() : explode(' ', $str); | |
var_dump($arr); //(空配列) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment