Home » Php » How to Pass a multi-dimensional array to SOAP in PHP

How to Pass a multi-dimensional array to SOAP in PHP

Posted by: admin February 25, 2020 Leave a comment

Questions:

I need to pass a multi-dimensional array to a soap function. But I don’t know what the structure of the array should look like.

Here’s an excerpt from the WSDL:

<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="FunctionCode" type="xsd:int"/>
<xsd:element minOccurs="0" maxOccurs="1" name="Mandator" type="xsd:int"/>
xsd:element minOccurs="0" maxOccurs="1" name="Material" type="vt:ArrayOfCallMaterial"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

the ArrayOfCallMaterial:

<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="CallMaterial" type="vt:CallMaterial"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="CallMaterial">
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="id" type="xsd:string"/>
<xsd:element minOccurs="1" maxOccurs="1" name="quantity" type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>

This is how I’m constructing my parameter:

$requestParams = array(
            'FunctionCode' => 1,
            'Mandator' => 1,
            'Material' => $material,
);

The Material Array looks like:

Array
                (
                    [0] => Array
                        (
                            [id] => 55A000009
                            [quantity] => 1.0000
                        )

                    [1] => Array
                        (
                            [id] => 55A000001
                            [quantity] => 10.0000
                        )

                )

than i call the Service:

$response =  json_decode(json_encode($this->client->call($requestParams)), true);

the problem is, only the first element of the array is ever transferred. Can someone help me to build the right structure?

How to&Answers: