在PHP中嵌套函数


Nesting functions in PHP

简单的PHP问题:

,为什么这样做

$exclude_exts = array('js', 'css',);
$filename = "test.css";
$ext = explode('.',$filename);
$is_excluded = in_array(strtolower(array_pop($ext)), $exclude_exts);

但事实并非如此。

$exclude_exts = array('js', 'css',);
$filename = "test.css";
$is_excluded = in_array(strtolower(array_pop(explode('.',$filename))), $exclude_exts);

编辑:两者都曾在以前的PHP版本中工作(我忘了是哪个版本)。

因为array_pop需要引用,因为它会在适当的位置更改数组。当您传递explode的返回值时,那里没有可引用的变量。