PHP - Insert elemens into an array
<p>I'm working on a formular, but for the moment I just want to insert into an array my elements (I have books and authors).</p>

<p>I can display my books with author (name + surname) with the foreach, but I can't add more elements.</p>

<p>Here is the code with the form.</p>

<pre><code>&lt;H1&gt;Exercice 2&lt;/H1&gt;
&lt;form method="POST"&gt;
    &lt;label for"code" &gt;Number :&lt;/label&gt;
    &lt;input id="code" name="code" type="number" /&gt;

    &lt;label for"title"&gt;Title :&lt;/label&gt;
    &lt;input id="title" name="title" type="text" /&gt;

    &lt;label for"author" &gt;Author :&lt;/label&gt;
    &lt;input id="author" name="author" type="text" /&gt;
&lt;button type="input" type="submit"&gt;Ok&lt;/button&gt;
</code></pre>

<p>


<pre><code>$title =  $_POST['title']; 
$code = $_POST['code'];
$author = $_POST['author'];

$book = array();
$book['code'] = 123;
$book['title'] = "Legendes";
$book['author'] = array("David", "Gemmel");

foreach($book as $value){
    $book['key'] = $value;
    var_dump($book);
    if (is_array($value)) {
        foreach($value as $otherValue) {
            echo($otherValue);
        }
    } else {
        echo($value);
    }
}
</code></pre>

<p>I did some searcch, but I don't think it works, it's using the array_push() method with the POST, but I don't know where I can manipulate my form into the array.</p>

<p>If you want some details, I'll be happy to do that =) I'm working on it, if i have some news, you will know =)</p>

<p>Have a nice day =)</p>