1

I have posted parts of this.. but this a different question for it

i have the below

foreach ($results['comments'] as $item) {

  echo 'Date: '. $item['created_at'] .'<br/>';
  echo 'Description : '. $item['html_body'] .'<br/>';
  echo 'Attachments : '. $item['attacments->url'] .'<br/>';
  echo 'Filename : '. $item['file_name'] .'<br/>';
  echo "<br>";
}

So basically, my Date and Description work, BUT the attachments wont work, b/c i dont think thats the correct way to get an object thats within an array of an array? hope i explained it correctly.

the comments array has all the date as a single object and so is description, then it has this trailing.

[public] => 1 [trusted] => 1 [attachments] => Array ( [0] => Array ( [url] => https://url/api/v2/attachments/IDHERE.json [id] => ID#[file_name] => name of file here
user3100345
  • 41
  • 10

1 Answers1

2

Take a look at your array dump

[public] => 1
[trusted] => 1
[attachments] => Array (
    [0] => Array (
        [url] => https://url/api/v2/attachments/IDHERE.json
        [id] => ID#
        [file_name] => name of file here

Get the values like this:

$Attachments = $item['attachments'];
$AttachmentsUrl = $Attachments[0]['url'];
$Attachmentsid = $Attachments[0]['id'];
$AttachmentsFileName = $Attachments[0]['file_name'];
meda
  • 45,103
  • 14
  • 92
  • 122
  • can i ask, since the code is giving me an error of PHP Notice: Undefined offset: 0, can't i use the name of the array instead? how would that look @meda – user3100345 Feb 06 '14 at 19:47
  • @user3100345 if it throws an error, it means `$Attachments[0]` does not have any element at that index – meda Feb 06 '14 at 21:22
  • Should i put an if statement? – user3100345 Feb 06 '14 at 21:24
  • @user3100345 yes check if attachment array is set, maybe not all you comments have attachment, see this [answer](http://stackoverflow.com/a/18880670/1880431) coincidentally it simillar to your case – meda Feb 06 '14 at 21:42