tags:

views:

48

answers:

4

I'm total newbie to PHP and Drupal but I fix this simple(?) thingo on my template. I want to get title, date, text and link path from this array? I can't get it out of there. I think its because its in inside of another array and because im noob in PHP I cant get it out of there ? Also I would like to get it to a loop. If theres more content, I would get it as a list or something. I would use foreach for this? Like foreach $contents as $content and so on?

I get this output from this: var_dump($contents);

array
'total' => string '1' (length=1)
'data' => 
  array
    0 => 
      array
      'cid' => string '13231' (length=3)
      'title' => string 'TITLEBLABLABLA' (length=3)
      'body_text' => string 'TEXTBLABLABAL' (length=709)
      'created' => string '313131' (length=10)
      'created' => string '2010-07-13 14:12:11' (length=19)
      'path' => string 'http://goog.fi' (length=72)
A: 

RTFM: http://php.net/manual/en/language.types.array.php

Frxstrem
+1/-1. Rude, but a link to the correct documentation.
Douglas
If we all RTFM this site wouldn't exist.
Kevin
A: 

Think of accessing multidimensional arrays in the same way you'd access a file in a subdirectory: just reference each level/directory in sequence. Assuming that array is stored in $arr, you'd get the title as follows:

$arr['data']['0']['title']
Marc B
+1  A: 

Here is a basic PHP array tutorial

It comes down to this:

You retrieve an element of an array with []

$array = array( 'a' => 'b');
echo $array['a']; //Prints b;
Ikke
A: 

To loop through a multi-dimensional array and echo date try this...

foreach ($contents as $key => $content) {
        echo $content[$key]['created'];   
    }

If that doesn't work, post the output of print_r($content) in your question so I can't build you exact array. I'm kinda confused over the structure of your array in your question.

Mikey1980