0

Possible Duplicate:
Able to see a variable in print_r()'s output, but not sure how to access it in code

The output of print_r($node) is the following.

[field_pimage] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [fid] => 4
                            [alt] => 
                            [title] => 
                            [width] => 1440
                            [height] => 900
                            [uid] => 1
                            [filename] => 200801232112524201.jpg
                            [uri] => public://200801232112524201.jpg
                            [filemime] => image/jpeg
                            [filesize] => 122349
                            [status] => 1
                            [timestamp] => 1351403970

I want to output the [uri]'s value, how should I do it?

 $node->field_pimage->und->0->['uri'];  //but it doesn't work?
Community
  • 1
  • 1

5 Answers5

1

You are dealing with arrays, not objects.

So you either need $node->field_pimage['und'][0]['uri'] (if $node itself is an object) or $node['field_pimage']['und'][0]['uri'] (if $node is an array, too)

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
1

As it's an array... it should be accessed using...

$node['field_pimage']['und'][0]['uri'];
Brian
  • 8,418
  • 2
  • 25
  • 32
0
echo $node["field_pimage"]["und"]["0"]["uri"];
loler
  • 2,594
  • 1
  • 20
  • 30
  • I didn't down vote but - you need single quotes – Chris Nov 01 '12 at 12:30
  • 3
    you don't **need** single quotes, the performance gain from doing so would be negligible. Do whatever is more readable for yourself – SubjectCurio Nov 01 '12 at 12:40
  • Ah - I didn't realise there was a preformance gain, just makes it easier to read! I should have phrased it better sorry! ^^ – Chris Nov 01 '12 at 12:44
  • 1
    I always write strings with double quotes if it's possible, this is usual for ppl who started with something like `VB`. And for performance it's impossibly negligible. So as @MLeFevre said `I do whatever is more readable for me` :) – loler Nov 01 '12 at 12:51
0

Since they are all arrays you can use this syntax;

$node['field_pimage']['und'][0]['uri'];
Garvin
  • 477
  • 2
  • 10
0

It's a multidimensional array.

Work down the hierarchy of the array.

$uri = $node['field_pimage']['und'][0]['uri'];

print($uri);
EM-Creations
  • 4,195
  • 4
  • 40
  • 56