Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这就是我所拥有的:
$namex = $xml->xpath("//a[@b=foo]/c"); $name = $namex[0]; echo $name;
它起作用了,因为第一行创建了一个数组,第二行读取了第一个条目。有没有办法将两条线结合起来立即获得预期的结果?
您可以使用list:
list
list($name) = $xml->xpath("//a[@b=foo]/c");
有没有办法将两条线结合起来立即获得预期的结果?
是的和不...
PHP 5.4+:
echo $xml->xpath("//a[@b=foo]/c")[0]; // array dereferencing, yay!
PHP < 5.4:
$names = $xml->xpath("//a[@b=foo]/c"); echo $names[0];