Passing array to SOAP function in PHP(将数组传递给 PHP 中的 SOAP 函数)
本文介绍了将数组传递给 PHP 中的 SOAP 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我似乎找不到以数组为参数创建函数请求的方法.例如,我如何使用 PHP SoapClient 发出这种请求:
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>
是否可以在不创建任何额外类的情况下调用此函数(仅使用数组)?如果不是,最简洁的调用方式是什么?
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 函数将数组转换为对象树:
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);
这篇关于将数组传递给 PHP 中的 SOAP 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:将数组传递给 PHP 中的 SOAP 函数
基础教程推荐
猜你喜欢
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01