Jump to content

Need some help with arrays!


melsom

Recommended Posts

Hello,

 

I'm trying to extract information about a ticket through osTicket SOAP API, but I can't seem to figure out how!

 

This is the return from the script (var_dump):

 

array(1) {
  [0]=>
  object(stdClass)#2 (2) {
    ["question"]=>
    object(stdClass)#3 (4) {
      ["id"]=>
      int(25)
      ["created"]=>
      string(25) "2011-01-05T01:19:43+01:00"
      ["name"]=>
      string(4) "test"
      ["message"]=>
      string(4) "qasd"
    }
    ["answers"]=>
    array(1) {
      [0]=>
      object(stdClass)#4 (4) {
        ["id"]=>
        int(25)
        ["created"]=>
        string(25) "2011-01-05T01:25:06+01:00"
        ["name"]=>
        string(17) "Andreas Haakonsen"
        ["message"]=>
        string(3) "ler"
      }
    }
  }
}

 

A ticket can have several answers.

 

I just can't seem to figure out how to extract/use this data and present it on my webpage. Too many arrays for me to understand I guess :P

 

Is there anyone who can help me with some small code to help me figure this one out?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/223464-need-some-help-with-arrays/
Share on other sites

Something like this should work:

 

$question = $array[0]->question;
echo $question->name;
echo $question->message;

$answers = $array[0]->answers;

foreach($answers as $answer) {
   echo $answer->name;
   echo $answer->message;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.