2017-02-23 85 views
-2

我在PHP編碼是新的,我想在動態的多陣列增加一些變量的值,下面是我的代碼...插入值到PHP多陣列

$books = array (
     "finality"=> array (
     "title" => 1, 
     "author" => 2, 
     "thumbnail" => 3, 
     "file" => 4, 
     "comment" => 5, 
    ), 
    "science"=> array (
     "title" => 1, 
     "author" => 2, 
     "thumbnail" => 3, 
     "file" => 4, 
     "comment" => 5, 
    ), 
    "morality"=> array (
     "title" => 1, 
     "author" => 2, 
     "thumbnail" => 3, 
     "file" => 4, 
     "comment" => 5, 
    ), 
) 

我想添加變量等。 $ title,$ author,$ pic2,$ pic,$ comment,在$ books ['morality']之類的數組中。請幫幫我。

回答

0

如果我正確地解決了你的問題,這就是你想要的。

$books['morality']['title'] = $title; 
$books['morality']['author'] = $author; 
$books['morality']['thumbnail'] = $pic2; 
$books['morality']['file'] = $pic; 
$books['morality']['comment'] = $comment; 

如果這不是你正在尋找的嘗試,並在你想完成什麼更準確。

0

從我的理解,你想添加一個新的項目數組。

以下看起來像你需要什麼?如果不是,你能否試着澄清你想要的是什麼?

$books[ $category ] = array(
    "title" => $title, 
    "author" => $author, 
    "thumbnail" => $thumbnail, 
    "file" => $file, 
    "comment" => $comment 
);