2009-02-23 4 views
9

인사말,PHP에서 배열을 SOAP 함수에 전달하는 중

배열을 인수로 사용하여 함수 요청을 생성하는 방법을 찾지 못하는 것 같습니다.

<GetResultList> 
    <GetResultListRequest> 
    <Filters> 
     <Filter> 
     <Name>string</Name> 
     <Value>string</Value> 
     </Filter> 
     <Filter> 
     <Name>string</Name> 
     <Value>string</Value> 
     </Filter> 
    </Filters> 
    </GetResultListRequest> 
</GetResultList> 

가 (단지 배열을 사용하여) 여분의 클래스를 작성하지 않고이 함수를 호출이 가능 : 예를 들어, 내가 어떻게 PHP SoapClient를 사용하여 이러한 종류의 요청을해야합니까? 그렇지 않다면, 그것을 부르는 가장 간단한 방법은 무엇입니까? 그래서 같이

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; 
} 

:

답변

6

당신은 객체 트리에 배열을 변환하려면이 -v 기능을 사용할 수 있습니다 예를 들어

$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); 
+1

고맙습니다. 그것은 완벽하게 작동합니다! 실제로 "필터"=> 배열 "부분을 찾을 수 없습니다. – bezmax

-1

, 당신이 시도 할 수 있습니다 :

$data1 = new SampleStruct(); 
$data1->title="Hello world"; 
$data1->description="This is a sample description."; 

$data2 = new SampleStruct(); 
$data2->title="Hello world 2"; 
$data2->description="This is a sample description 2."; 

$client->__soapCall("sampleFunction", array(
    new SoapParam(new SoapVar(array($data1, $data2) , SOAP_ENC_ARRAY, 
     "SampleStruct_Array", "http://www.w3.org/2001/XMLSchema"), 
     "theSampleFunctionParamName") 
)); 
+0

이것은 질문에 대답하지 않습니다. – Tom