Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I made a Soap request that gives me an array filled with STDclasses.

I want the results from the Articlesummary so i can use the ID's for finding the right articles.

But all code i tried for now gives me problems with the STDclass and array combination

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

=} } } }

Can somebody help me please too find a way to get the results.

<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) } } } } }
share|improve this question
1  
Can you please view the page source of the object you called var_dump() or print_r() on and copy/paste from the source? After pasting it here, highlight and ctl-k to format a code block. This is incomprehensible as it is. – Michael Berkowski Oct 14 '12 at 13:17
I updated my first post – user1744878 Oct 14 '12 at 13:44

2 Answers

up vote 0 down vote accepted

You have an outer array which is associative. Its only key is GetArticleSummariesResult. ArticleSummaries is an object in that array having one property ArticleSummary, which is an array of objects. The values you are looking for (ID) are object properties.

$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 ->

Examples:

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

In a loop:

foreach ($outer_array['GetArticleSummariesResult']->ArticleSummaries->ArticleSummary as $summary) {
  // Print the id and created date
  echo $summary->ID . " " . $summary->Created . "\n";
}
share|improve this answer
That gives also the same Fatal error: Cannot use object of type stdClass as array – user1744878 Oct 14 '12 at 14:00
@user1744878 I updated above. I misread your output due to its missing indentation. – Michael Berkowski Oct 14 '12 at 14:00
@user1744878 I just updated it as you were commenting. See above now -- ArticleSummaries is an object inside GetArticleSummariesResult – Michael Berkowski Oct 14 '12 at 14:01
Still the same Fatal Error i'am trying now several options – user1744878 Oct 14 '12 at 14:11
@user1744878 Like I originally asked, view the page source of the dumped object, so you can see all the correct indentation. Copy it into your question with the indentation intact, highlight and ctl-k. – Michael Berkowski Oct 14 '12 at 14:12
show 7 more comments
    $result = array(); //your result

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

       //Search ID u want
       if($sum->ID == 009831)
          {
              //I got you.
          }
     }
share|improve this answer
That results in Cannot use object of type stdClass as array. That eeror i got the whole day. – user1744878 Oct 14 '12 at 13:48
yes, check the code again. i edited my 1st answer. thx – Nwafor Oct 14 '12 at 14:03
$result = $client->GetArticleSummaries(array('ArticleId')); $array = (array)$result; var_dump($array); – user1744878 Oct 14 '12 at 14:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.