Portal Home > Knowledgebase > Articles Database > Need help with arrays!


Need help with arrays!




Posted by terrahost, 01-04-2011, 08:42 PM
Hello, Im trying to communicate with the following API for osTicket: http://www.cyberde.nl/software-en-US...t-getmessages/ But I can't seem to understand how to really retrieve the data and manage it. I'm connecting to it with the following code: Where $result is returning the string as explained on the webpage. The ticket can contain several messages. Need to present them on a webpage in an easy way. Been trying chains of "foreach", but I just get lost :-/ Could anyone help me out with this one?

Posted by Evilzebra, 01-04-2011, 11:16 PM
var_dump() should display any data if there is any. If not the API should hopefully at least return false.

Posted by terrahost, 01-05-2011, 03:55 AM
That is exactly right, thank you! Now its just to figure out how to output these arrays in a proper way on a webpage..

Posted by terrahost, 01-05-2011, 06:23 AM
Is there anyone there who can help me figure this one out? Thanks!

Posted by Hostify Networks, 01-05-2011, 10:44 AM
print_r will give you something that's a little easier to work with. There are some great examples here: http://php.net/print_r The output of print_r will put the names of the different arrays in brackets (just like var_dump does...only with no info about the type of data). It should be something like $result[0][answers][0], $result[0][answers][1], etc. So if you wanted to see the message of reply number 2, you'd do $result[0][answers][1][message] and of course you could use foreach for this.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read