2012-10-14 98 views
1

我做了一個Soap請求,它給了我一個填充了STDclasses的數組。對於帶有stdclass對象的數組的PHP Soap請求

我想要從Articlesummary的結果,所以我可以使用ID來找到正確的文章。

但是,所有的代碼,我嘗試了,現在讓我用一個StdClass問題和陣列組合

array(1) { 

["GetArticleSummariesResult"]=> object(stdClass) 
#3 (2) { ["Errors"]=> object(stdClass)#4 (0) { } 

["ArticleSummaries"]=> object(stdClass)#5 (1) { 

["ArticleSummary"]=> array(27) { 
[0]=> object(stdClass)#6 (4) { ["ID"]=> int(21557) ["Created"]=> string(19) "2010-05-06  15:54:50" ["Modified"]=> string(19) "2010-05-25 19:54:09" ["Active"]=> bool(true) } 
[1]=> object(stdClass)#7 (4) { ["ID"]=> int(21638) ["Created"]=> string(19) "2010-05-06 15:54:50" ["Modified"]=> string(19) "2010-05-25 19:54:09" ["Active"]=> bool(true) } 
[2]=> object(stdClass)#8 (4) { ["ID"]=> int(21260) ["Created"]=> string(19) "2010-05-06 15:54:50" ["Modified"]=> string(19) "2010-05-25 19:54:09" ["Active"]=> bool(true) } 
[3]=> object(stdClass)#9 (4) { ["ID"]=> int(26664) ["Created"]=> string(19) "2010-05-25 19:54:07" ["Modified"]=> string(19) "2010-05-25 19:54:07" ["Active"]=> bool(true) } 
[4]=> object(stdClass)#10 (4) { ["ID"]=> int(22165) ["Created"]=> string(19) "2010-05-25 19:54:07" ["Modified"]=> string(19) "2010-05-25 19:54:07" ["Active"]=> bool(true) } 
[5]=> object(stdClass)#11 (4) { ["ID"]=> int(24166) ["Created"]=> string(19) "2010-05-25 19:54:07" ["Modified"]=> string(19) "2010-08-16 22:44:38" ["Active"]=> bool(true) } 
[6]=> object(stdClass)#12 (4) { ["ID"]=> int(26167) ["Created"]=> string(19) "2010-05-25 19:54:07" ["Modified"]=> string(19) "2010-05-25 19:54:07" ["Active"]=> bool(true) } 
[7]=> object(stdClass)#13 (4) { ["ID"]=> int(26170) ["Created"]=> string(19) "2010-05-25 19:54:07" ["Modified"]=> string(19) "2011-05-05 09:04:19" ["Active"]=> bool(true) } 
[8]=> object(stdClass)#14 (4) { ["ID"]=> int(29471) ["Created"]=> string(19) "2010-07-02 11:59:26" ["Modified"]=> string(19) "2010-07-02 11:59:26" ["Active"]=> bool(true) } 
[9]=> object(stdClass)#15 (4) { ["ID"]=> int(21157) ["Created"]=> string(19) "2011-03-04 09:34:11" ["Modified"]=> string(19) "2012-06-12 11:34:44" ["Active"]=> bool(true) } 
[10]=> object(stdClass)#16 (4) { ["ID"]=> int(272876) ["Created"]=> string(19) "2011-04-11 12:14:29" ["Modified"]=> string(19) "2012-09-04 14:25:07" ["Active"]=> bool(true) } 
[11]=> object(stdClass)#17 (4) { ["ID"]=> int(28328) ["Created"]=> string(19) "2011-05-03 12:25:07" ["Modified"]=> string(19) "2011-05-03 12:25:07" ["Active"]=> bool(true) } 
[12]=> object(stdClass)#18 (4) { ["ID"]=> int(226752) ["Created"]=> string(19) "2011-05-17 00:14:51" ["Modified"]=> string(19) "2011-05-25 10:48:22" ["Active"]=> bool(true) } 
[13]=> object(stdClass)#19 (4) { ["ID"]=> int(2231971) ["Created"]=> string(19) "2011-05-18 16:37:50" ["Modified"]=> string(19) "2011-05-18 16:40:12" ["Active"]=> bool(true) } 
[14]=> object(stdClass)#20 (4) { ["ID"]=> int(2970219) ["Created"]=> string(19) "2011-09-05 10:34:14" ["Modified"]=> string(19) "2011-09-05 10:34:14" ["Active"]=> bool(true) } 
[15]=> object(stdClass)#21 (4) { ["ID"]=> int(24178) ["Created"]=> string(19) "2011-11-18 18:54:16" ["Modified"]=> string(19) "2011-11-23 13:44:18" ["Active"]=> bool(true) } 
[16]=> object(stdClass)#22 (4) { ["ID"]=> int(3160171) ["Created"]=> string(19) "2012-01-18 10:55:09" ["Modified"]=> string(19) "2012-01-18 14:04:18" ["Active"]=> bool(true) } 
[17]=> object(stdClass)#23 (4) { ["ID"]=> int(394795) ["Created"]=> string(19) "2012-02-10 10:14:15" ["Modified"]=> string(19) "2012-02-10 10:14:16" ["Active"]=> bool(true) } 
[18]=> object(stdClass)#24 (4) { ["ID"]=> int(3236961) ["Created"]=> string(19) "2012-03-12 11:44:45" ["Modified"]=> string(19) "2012-03-12 13:34:37" ["Active"]=> bool(true) } 
[19]=> object(stdClass)#25 (4) { ["ID"]=> int(343578) ["Created"]=> string(19) "2012-06-07 15:24:07" ["Modified"]=> string(19) "2012-06-11 09:44:22" ["Active"]=> bool(true) } 
[20]=> object(stdClass)#26 (4) { ["ID"]=> int(3376400) ["Created"]=> string(19) "2012-07-03 13:55:40" ["Modified"]=> string(19) "2012-07-03 13:55:40" ["Active"]=> bool(true) } 
[21]=> object(stdClass)#27 (4) { ["ID"]=> int(33622) ["Created"]=> string(19) "2012-07-25 10:24:24" ["Modified"]=> string(19) "2012-07-25 10:24:24" ["Active"]=> bool(true) } 
[22]=> object(stdClass)#28 (4) { ["ID"]=> int(3404088) ["Created"]=> string(19) "2012-07-25 14:34:20" ["Modified"]=> string(19) "2012-07-25 14:34:20" ["Active"]=> bool(true) } 
[23]=> object(stdClass)#29 (4) { ["ID"]=> int(35046) ["Created"]=> string(19) "2012-07-26 15:14:13" ["Modified"]=> string(19) "2012-08-20 11:04:20" ["Active"]=> bool(true) } 
[24]=> object(stdClass)#30 (4) { ["ID"]=> int(37926) ["Created"]=> string(19) "2012-09-04 14:44:09" ["Modified"]=> string(19) "2012-09-04 14:44:09" ["Active"]=> bool(true) } 
[25]=> object(stdClass)#31 (4) { ["ID"]=> int(36657) ["Created"]=> string(19) "2012-09-17 16:14:53" ["Modified"]=> string(19) "2012-09-17 16:14:53" ["Active"]=> bool(true) } 
[26]=> object(stdClass)#32 (4) { ["ID"]=> int(32328) ["Created"]=> string(19) "2012-10-08 10:34:42" ["Modified"]=> string(19) "2012-10-08 10:44:33" ["Active"]=> bool(true) } 

=} } } } 

有人可以幫我請得找到一種方式來獲得滿意的結果。

<wsdl:operation name="GetArticleSummaries"><wsdl:documentation>Get publication summaries for publications that where last created/modified after the given date. 
       lastModified not specified will return all active publications. 
       RequestedPropertyTypes (PropertyTypes) not specified will return all allowed types. 
       Please use RequestedPropertyTypes instead of PropertyTypes, PropertyTypes will be removed in future versions.</wsdl:documentation><wsdl:input message="tns:GetPublicationSummariesSoapIn"/><wsdl:output message="tns:GetPublicationSummariesSoapOut"/> 


<wsdl:message name="GetArticleSummariesSoapIn"><wsdl:part name="parameters" element="tns:GetPublicationSummaries"/></wsdl:message> 


<s:element name="GetArticleSummaries"><s:complexType><s:sequence><s:element minOccurs="1" maxOccurs="1" name="LastModified" nillable="true" type="s:dateTime"/><s:element minOccurs="0" maxOccurs="unbounded" name="PropertyTypes" type="tns:PropertyType"/><s:element minOccurs="0" maxOccurs="1" name="RequestedPropertyTypes" type="tns:ArrayOfPropertyType"/></s:sequence></s:complexType></s:element> 




$result = $client->GetArticleSummaries(array('ArticleId')); 
$array = (array)$result; 
var_dump($array); 








object(stdClass)#2 (1) { ["GetPublicationSummariesResult"]=> object(stdClass)#3 (2) { ["Errors"]=> object(stdClass)#4 (0) { } ["PublicationSummaries"]=> object(stdClass)#5 (1) { ["PublicationSummary"]=> array(27) { [0]=> object(stdClass)#6 (4) { ["ID"]=> int(1441657) ["Created"]=> string(19) "2010-05-06 15:54:50" ["Modified"]=> string(19) "2010-05-25 19:54:09" ["Active"]=> bool(true) } [1]=> object(stdClass)#7 (4) { ["ID"]=> int(1441658) ["Created"]=> string(19) "2010-05-06 15:54:50" ["Modified"]=> string(19) "2010-05-25 19:54:09" ["Active"]=> bool(true) } [2]=> object(stdClass)#8 (4) { ["ID"]=> int(1441660) ["Created"]=> string(19) "2010-05-06 15:54:50" ["Modified"]=> string(19) "2010-05-25 19:54:09" ["Active"]=> bool(true) } [3]=> object(stdClass)#9 (4) { ["ID"]=> int(1456164) ["Created"]=> string(19) "2010-05-25 19:54:07" ["Modified"]=> string(19) "2010-05-25 19:54:07" ["Active"]=> bool(true) } [4]=> object(stdClass)#10 (4) { ["ID"]=> int(1456165) ["Created"]=> string(19) "2010-05-25 19:54:07" ["Modified"]=> string(19) "2010-05-25 19:54:07" ["Active"]=> bool(true) } [5]=> object(stdClass)#11 (4) { ["ID"]=> int(1456166) ["Created"]=> string(19) "2010-05-25 19:54:07" ["Modified"]=> string(19) "2010-08-16 22:44:38" ["Active"]=> bool(true) } [6]=> object(stdClass)#12 (4) { ["ID"]=> int(1456167) ["Created"]=> string(19) "2010-05-25 19:54:07" ["Modified"]=> string(19) "2010-05-25 19:54:07" ["Active"]=> bool(true) } [7]=> object(stdClass)#13 (4) { ["ID"]=> int(1456170) ["Created"]=> string(19) "2010-05-25 19:54:07" ["Modified"]=> string(19) "2011-05-05 09:04:19" ["Active"]=> bool(true) } [8]=> object(stdClass)#14 (4) { ["ID"]=> int(1489471) ["Created"]=> string(19) "2010-07-02 11:59:26" ["Modified"]=> string(19) "2010-07-02 11:59:26" ["Active"]=> bool(true) } [9]=> object(stdClass)#15 (4) { ["ID"]=> int(1721157) ["Created"]=> string(19) "2011-03-04 09:34:11" ["Modified"]=> string(19) "2012-06-12 11:34:44" ["Active"]=> bool(true) } [10]=> object(stdClass)#16 (4) { ["ID"]=> int(1772876) ["Created"]=> string(19) "2011-04-11 12:14:29" ["Modified"]=> string(19) "2012-09-04 14:25:07" ["Active"]=> bool(true) } [11]=> object(stdClass)#17 (4) { ["ID"]=> int(1808328) ["Created"]=> string(19) "2011-05-03 12:25:07" ["Modified"]=> string(19) "2011-05-03 12:25:07" ["Active"]=> bool(true) } [12]=> object(stdClass)#18 (4) { ["ID"]=> int(1826752) ["Created"]=> string(19) "2011-05-17 00:14:51" ["Modified"]=> string(19) "2011-05-25 10:48:22" ["Active"]=> bool(true) } [13]=> object(stdClass)#19 (4) { ["ID"]=> int(1830971) ["Created"]=> string(19) "2011-05-18 16:37:50" ["Modified"]=> string(19) "2011-05-18 16:40:12" ["Active"]=> bool(true) } [14]=> object(stdClass)#20 (4) { ["ID"]=> int(1970219) ["Created"]=> string(19) "2011-09-05 10:34:14" ["Modified"]=> string(19) "2011-09-05 10:34:14" ["Active"]=> bool(true) } [15]=> object(stdClass)#21 (4) { ["ID"]=> int(2084178) ["Created"]=> string(19) "2011-11-18 18:54:16" ["Modified"]=> string(19) "2011-11-23 13:44:18" ["Active"]=> bool(true) } [16]=> object(stdClass)#22 (4) { ["ID"]=> int(2160171) ["Created"]=> string(19) "2012-01-18 10:55:09" ["Modified"]=> string(19) "2012-01-18 14:04:18" ["Active"]=> bool(true) } [17]=> object(stdClass)#23 (4) { ["ID"]=> int(2194795) ["Created"]=> string(19) "2012-02-10 10:14:15" ["Modified"]=> string(19) "2012-02-10 10:14:16" ["Active"]=> bool(true) } [18]=> object(stdClass)#24 (4) { ["ID"]=> int(2236961) ["Created"]=> string(19) "2012-03-12 11:44:45" ["Modified"]=> string(19) "2012-03-12 13:34:37" ["Active"]=> bool(true) } [19]=> object(stdClass)#25 (4) { ["ID"]=> int(2343578) ["Created"]=> string(19) "2012-06-07 15:24:07" ["Modified"]=> string(19) "2012-06-11 09:44:22" ["Active"]=> bool(true) } [20]=> object(stdClass)#26 (4) { ["ID"]=> int(2376900) ["Created"]=> string(19) "2012-07-03 13:55:40" ["Modified"]=> string(19) "2012-07-03 13:55:40" ["Active"]=> bool(true) } [21]=> object(stdClass)#27 (4) { ["ID"]=> int(2403622) ["Created"]=> string(19) "2012-07-25 10:24:24" ["Modified"]=> string(19) "2012-07-25 10:24:24" ["Active"]=> bool(true) } [22]=> object(stdClass)#28 (4) { ["ID"]=> int(2404088) ["Created"]=> string(19) "2012-07-25 14:34:20" ["Modified"]=> string(19) "2012-07-25 14:34:20" ["Active"]=> bool(true) } [23]=> object(stdClass)#29 (4) { ["ID"]=> int(2405046) ["Created"]=> string(19) "2012-07-26 15:14:13" ["Modified"]=> string(19) "2012-08-20 11:04:20" ["Active"]=> bool(true) } [24]=> object(stdClass)#30 (4) { ["ID"]=> int(2447926) ["Created"]=> string(19) "2012-09-04 14:44:09" ["Modified"]=> string(19) "2012-09-04 14:44:09" ["Active"]=> bool(true) } [25]=> object(stdClass)#31 (4) { ["ID"]=> int(2466657) ["Created"]=> string(19) "2012-09-17 16:14:53" ["Modified"]=> string(19) "2012-09-17 16:14:53" ["Active"]=> bool(true) } [26]=> object(stdClass)#32 (4) { ["ID"]=> int(2502328) ["Created"]=> string(19) "2012-10-08 10:34:42" ["Modified"]=> string(19) "2012-10-08 10:44:33" ["Active"]=> bool(true) } } } } } 
+1

能否請您查看的對象的頁面的源代碼,你叫'的var_dump()'或'的print_r( )'並從源文件複製/粘貼?在粘貼之後,突出顯示和ctl-k格式化代碼塊。這是不可理解的。 –

+0

我更新了我的第一篇文章 – user1744878

回答

0

你有一個關聯的外部數組。它唯一的關鍵是GetArticleSummariesResultArticleSummaries是該數組中具有一個屬性ArticleSummary的對象,它是一個對象數組。您正在查找的值(ID)是對象屬性。

$outer_array: array, access with [] 
GetArticleSummariesResult: object stdClass 
ArticleSummaries: object stdClass, access properties with -> 
ArticleSummary: array with numeric indices, access with [] 
Objects in ArticleSummary array: object stdClass, access properties with -> 

例子:

echo $outer_array['GetArticleSummariesResult']->ArticleSummaries->ArticleSummary[0]->ID; 
// 21557 
echo $outer_array['GetArticleSummariesResult']->ArticleSummaries->ArticleSummary[0]->Created; 
// 2010-05-06  15:54:50 
echo $outer_array['GetArticleSummariesResult']->ArticleSummaries->ArticleSummary[5]->ID; 
// 24166 

在一個循環:

foreach ($outer_array['GetArticleSummariesResult']->ArticleSummaries->ArticleSummary as $summary) { 
    // Print the id and created date 
    echo $summary->ID . " " . $summary->Created . "\n"; 
} 
+0

這也給出了同樣的致命錯誤:不能使用類型爲stdClass的對象作爲數組 – user1744878

+0

@ user1744878我上面已更新。由於缺少縮進,我誤解了您的輸出。 –

+0

@ user1744878我剛剛在評論時更新了它。現在看上面 - 'ArticleSummaries'是'GetArticleSummariesResult'裏面的一個對象' –

0
$result = array(); //your result 

    foreach($result["GetArticleSummariesResult"]->ArticleSummaries->ArticleSummary as $sum) 
    { 

     //Search ID u want 
     if($sum->ID == 009831) 
      { 
       //I got you. 
      } 
    } 
+0

導致無法使用stdClass類型的對象作爲數組。那天我得到了整整一天。 – user1744878

+0

是的,再次檢查代碼。我編輯了我的第一個答案。thx – Nwafor

+0

$ result = $ client-> GetArticleSummaries(array('ArticleId')); $ array =(array)$ result; var_dump($ array); – user1744878