2012-09-25 58 views
0

在WordPress我有一個數據結構是這樣的:訪問字符串中對象的內部數組

array 
    49 => 
    object(stdClass)[272] 
     public 'ID' => int 49 
     ... 
     // I need this guid 
     public 'guid' => string 'http://localhost/github/wordpress/wp-content/uploads/2012/09/3.png' (length=66) 
     ... 
    47 => 
    object(stdClass)[275] 

    46 => 
    object(stdClass)[276] 
     public 'ID' => int 46 
     ... 
     public 'filter' => string 'raw' (length=3) 

我試圖訪問​​和這個作品:

$temp121212 = get_children($post->ID); 
echo $temp121212[49]->guid; 

但這並不:

echo get_children($post->ID)[49]->guid; 

我在做什麼錯?這不能這樣做嗎?

回答

0

截至PHP 5.3,你不能[你在JavaScript中一樣,例如 - 這就是所謂的數組語法。

所以,你必須保存您的陣列的地方:

$child = get_children($post->ID)[49]; 
echo $child -> guid; 

在PHP 5.4然而,你被允許使用的語法。