本文介紹了將數(shù)組傳遞給 PHP 中的 SOAP 函數(shù)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
您好,
我似乎找不到以數(shù)組為參數(shù)創(chuàng)建函數(shù)請求的方法.例如,我如何使用 PHP SoapClient 發(fā)出這種請求:
I can't seem to find a way to create a function request with array as an argument. For example, how do I make this kind of request using PHP SoapClient:
<GetResultList>
<GetResultListRequest>
<Filters>
<Filter>
<Name>string</Name>
<Value>string</Value>
</Filter>
<Filter>
<Name>string</Name>
<Value>string</Value>
</Filter>
</Filters>
</GetResultListRequest>
</GetResultList>
是否可以在不創(chuàng)建任何額外類的情況下調(diào)用此函數(shù)(僅使用數(shù)組)?如果不是,最簡潔的調(diào)用方式是什么?
Is this possible to call this function without creating any extra classes (using arrays only)? If no, what is the most compact way of calling it?
推薦答案
您可以使用這個 -v 函數(shù)將數(shù)組轉(zhuǎn)換為對象樹:
You can use this -v function to convert a array to a object tree:
function array_to_objecttree($array) {
if (is_numeric(key($array))) { // Because Filters->Filter should be an array
foreach ($array as $key => $value) {
$array[$key] = array_to_objecttree($value);
}
return $array;
}
$Object = new stdClass;
foreach ($array as $key => $value) {
if (is_array($value)) {
$Object->$key = array_to_objecttree($value);
} else {
$Object->$key = $value;
}
}
return $Object;
}
像這樣:
$data = array(
'GetResultListRequest' => array(
'Filters' => array(
'Filter' => array(
array('Name' => 'string', 'Value' => 'string'), // Has a numeric key
array('Name' => 'string', 'Value' => 'string'),
)
)
)
);
$Request = array_to_objecttree($data);
這篇關于將數(shù)組傳遞給 PHP 中的 SOAP 函數(shù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!