I want to append the key from $teasers to the key of the array contained within each $teasers element and then create an associative array that contains the appended keys for its key and the content of the sub array for its content. Following? I hope so, if not here’s an example of my desired end product:
This is a simplified version of the multidimensional array I’m working with:
$teasers[0]=array('id' => 4,
'title' => 'How to determine the speed of an african swallow',
'content'=> 'Its really quite simple...')
$teasers[1]=array('id' => 5,
'title' => 'Man alleged to be cereal killer after breakfast',
'content' => 'Turns out eating a delicious bowl of froste...')
I’m working towards turning it into this:
$data Array(
'/*Key from subarray+$teasers key*/' => '/*content from subarray*/',
'id0' => '4',
'title0' => 'How to determine the speed of an african swallow',
'content0' => 'Its really quite simple...',
'id1' => '5',
'title1' => 'Man alleged to be cereal killer after breakfast',
'content1' => 'Turns out eating a delicious bowl of frosted...')
Still not following? I don’t blame you. Maybe this will help. I was originally going about it like this until I realized you can’t pass a variable into a foreach loop. ):
foreach ($teasers as $key => $blogentry) {
foreach($blogentry as $entrykey => $content){
//Basically I would like to append $key to the end of $entrykey
//so that I can essentially access all of the data from one array($data[])
$data[$entrykey.$key] = $content;
}
}
I’m more than happy to do anything I can to make things more clear or help you help me. Thanks for your time in advance!!
I think your code should work. Add
$data = array();before your loops.