我使用break来破坏一个FQDN,并将它存储在一个数组中。但是,调用该数组上的pop返回一个空白或空字符串,我不知道为什么。
$domains = explode(".",str_replace("example.com","","test.example.com"));
print "Test: " . $domains[0] . "<br>";
$target = array_pop($domains);
print "Target: " . $target . "<br>";运行上述代码将得到以下结果:
Test: test
Target: 为什么$target不包含“测试”?
发布于 2013-11-29 22:42:08
实际上,这就是你实际上在做的事情:
var_dump(explode('.', 'test.'));
array(2) {
[0]=>
string(4) "test"
[1]=>
string(0) ""
}数组中有两个元素:"test“和句点之后的内容,即空字符串。
发布于 2013-11-29 22:43:44
array_pop()弹出并返回数组的最后一个值
使用移位
https://stackoverflow.com/questions/20294260
复制相似问题