Welcome Guest, Not a member yet? Register   Sign In
accessing array data - please help!
#1

[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
                )

        )
)
#2

[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


}

}

}




Theme © iAndrew 2016 - Forum software by © MyBB