XPATH - get single value returned instead of array php

后端 未结 5 1353
不知归路
不知归路 2021-01-15 01:02

I am using Xpath in PHP - I know that my query will return either 0 or 1 results.

If 1 result is returned I do not want it as an array - which is what is returned ri

5条回答
  •  清酒与你
    2021-01-15 01:26

    You can write it most simply like this:

    $string = @$array[0];
    

    The @ operator will suppress errors, making $string null if $array is empty.

提交回复
热议问题