2
$ teasers要素に含まれる配列のキーに$ teasersのキーを追加し、そのキーの追加キーとその内容のサブ配列の内容を含む連想配列を作成します。以下?私はそう願って、そうでない場合はここに私の所望の最終製品の一例です:exitsting配列キーに文字列を追加しますか? PHP
これは、私が働いている多次元配列の簡易版である:
$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...')
私はこれにそれを回すに向けて取り組んでいます:
$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...')
まだありませんか?私はあなたを責めません。多分これが助けになるでしょう。私はあなたがforeachループに変数を渡すことができないことに気付くまで、私は元来このように行っていました。 ):
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;
}
}
私は物事をより明確にするか、あなたを助けてくれることができます。事前にお時間をありがとう!
'foreachループに変数を渡すことができないことに気付くまで、私はもともとこのように行っていました。 ): '??? – ajreal
あなたのコードは正常に動作しています " – anubhava
ああ、申し訳ありませんが、IDKは私が次のループに$ keyを渡すことができなかったように見えるようにしていました。回答を読んだ後、私はここに貼り付けたものをコピーし、POOFはそれを動作させます。私の脳は濃いです。私はプログラミングの世界とその犠牲者を奪うことのできない新しさです。 この投稿を削除する必要がありますか? – Austin