简体   繁体   中英

Soap Client Method parameter array omits keys - PHP

I'm trying to use the default SOAP Client of XAMPP PHP, i need to pass array as parameter to SoapClient method invocation, but the methos receives parameter without array keys,

MyCode:

$client = new SoapClient('http://localhost/crm/WSIn07/ws'); 
$data = array("name"=>"xxx","age"=>"32");
echo $client->UpdateEmp($data);

but in controller method the array prints as ["xxx","32"] so when i try to access $data["name"] it throws undefined index error : name

Please anyone provide me an idea to send array with keys to SOAPClient method

This string looks like a json, so you can use json_decode() function to convert this data (In your controller inside the function UpdateEmp) .

Use isset() and prevents undefined index error.

Try something like this:

$client = new SoapClient('http://localhost/crm/WSIn07/ws'); 
$data = array("name"=>"xxx","age"=>"32");

$decoded = json_decode($client->UpdateEmp($data));

if (isset($decoded["name"])) {
echo $decoded["name"];
}

if (isset($decoded["age"])) {
echo $decoded["age"];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM