简体   繁体   中英

how to access items in this stdClass Object that is return from php/soap?

i am using osticket api and had developed this function to integrate osticket into my web application:

    function ReadTicket($ticketID)
    {
     $osticket = new SoapClient('url');

    $args = array(

        'username'        => 'someuser',

        'password'        => 'some pass',

        'ticketID'        => 1234); 

    try {
        $result = $osticket->__call('ostTicket.getMessages',$args);



      print_r( $result  );    





}

catch (SoapFault $e) {

    throw $e;

} 
} 

and here is the result from print_r command:

Array ( [0] => stdClass Object ( [question] => stdClass Object ( [id] => 80 [created] => 2012-11-25T14:48:29-06:00 [name] => name [message] => body ) [answers] => Array ( [0] => stdClass Object ( [id] => 80 [created] => 2012-11-30T23:52:48-06:00 [name] => Admin Admin [message] => testttttttttt ) ) ) )

how to access the result and print out only id and message?

here is a reference to the soap call http://www.cyberde.nl/software-en-US/osticket-soap-mod/ostticket-getmessages/

foreach($result[0]['answer'] as $ans)//one ore more answers
 echo $ans['id']." '".$ans['message']."'<br/>";

it should be like $result[0]->question->id or for multiple results

foreach($result as $r){
  echo $r->question->id;
  foreach($r->answers as $answer){
    echo $answer->id;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM