CodeIgniter Forums
accessing array data - please help! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: accessing array data - please help! (/thread-13319.html)



accessing array data - please help! - El Forum - 11-18-2008

[eluser]new_igniter[/eluser]
Hello,
I am a lowly noob and having issues accessing data from this array. How would I grab the "postPic" string from the array below?

Code:
Array
(
    [0] => Array
        (
            [0] => stdClass Object
                (
                    [masterLinkID] => 21
                    [postUser] => mediaguardian
                    [postPic] => http://s3.amazonaws.com/twitter_production/profile_images/61616323/mediaguardian_normal.jpg
                    [postLink] => http://www.guardian.co.uk/media/2008/nov/18/wallace-gromit-bbc-television-christmas
                    [postID] => 1010490482
                    [postText] => Wallace & Gromit back for Christmas | Media | The Guardian
                    [postDate] => 2008-11-17 16:35:40
                    [postContent] => Nick Park brings pair back in 'more humane' 30-minute format after making two gruelling feature films http://bit.ly/16mPc
                    [postTitle] => Nick Park has brought the pair back in the 'more humane' 30-minute format after making two gruelling feature films. By Ben Dowell
                )

        )
)



accessing array data - please help! - El Forum - 11-18-2008

[eluser]alejandra[/eluser]
Hope this could help you, I recreate the code in the following way, took out the object.

$myarray = array(
0 => array
(
0 => array
(
'masterLinkID' => 21,
'postUser' => 'mediaguardian',
'postPic' => 'http://s3.amazonaws.com/twitter_production/profile_images/61616323/mediaguardian_normal.jpg',
'postLink' => 'http://www.guardian.co.uk/media/2008/nov/18/wallace-gromit-bbc-television-christmas',
'postID' => '1010490482',
'postText' => 'Wallace & Gromit back for Christmas | Media | The Guardian',
'postDate' => '2008-11-17 16:35:40',
'postContent' => "Nick Park brings pair back in 'more humane' 30-minute format after making two gruelling feature films http://bit.ly/16mPc",
'postTitle' => "Nick Park has brought the pair back in the 'more humane' 30-minute format after making two gruelling feature films. By Ben Dowell"
)

)
);


You can access it directly with the following code

echo $myarray[0][0]['postPic'];


You can use a for each too

foreach($myarray as $firstarray)
{
foreach($firstarray as $secondarray)
{
foreach($secondarray as $key => $value)
{

echo $key .'<br />'; //index
echo $value .'<br />'; //value


}

}

}