SOAP 结果 returns 负数但不能被 IF ELSE 识别

SOAP Result returns negative number but does not recognize by IF ELSE

我这里有一个 SOAP Web 服务请求 returns 一个负值,但是当我在 IF ELSE 方法上使用它时它无法识别并且条件总是转到 ELSE 即使值相等.请看下面的代码:

$url = 'http://0.0.0.0/webservice/SampleWebservice.asmx?WSDL';
$context = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
));
$rq = ["Value1" => "value",
"ClientKey" => "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"];
$service = new SoapClient($url, array('stream_context' => $context));
$xml = $service->GetWebServiceRequestVariable($rq);
$array = json_decode(json_encode($xml), true);
$value = $array['GetWebServiceRequestVariable_Result']['any'];
//value returns -1
if($value == -1) {
 echo 'Value is negative';
}
else {
echo 'Value is positive';
}
//returns Value is Positive

我找到了解决办法。我只是将值转换为 SimpleXMLElement 然后使用 json_encode 将其编码为 json 然后使用 json_decode 对其进行解码然后获取 json 元素

$url = 'http://0.0.0.0/webservice/SampleWebservice.asmx?WSDL';
$context = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
));

$rq = ["Value1" => "value",
"ClientKey" => "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"];
$service = new SoapClient($url, array('stream_context' => $context));
$xml = $service->GetWebServiceRequestVariable($rq);
$array = json_decode(json_encode($xml), true);

$xmljson = new SimpleXMLElement($array['GetWebServiceRequestVariable_Result']['any']);
$cvjson = json_encode($xmljson);
$bcjson = json_decode($cvjson,true);
$value = $bcjson["NewDataSet"]["Table"]["Value"];

if($value == -1) {
 echo 'Value is negative';
}
else {
echo 'Value is positive';
}
//now returns Value is negative