Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP stacking array in another using push
    primarykey
    data
    text
    <p>Could anyone explain me how to solve the following:</p> <pre><code>function GetSetClearForm(){ $person = array('firstname' =&gt; $_POST["fname"], 'lastname' =&gt; $_POST["lname"],'age' =&gt; $_POST["age"] ,'city' =&gt; $_POST["city"] ,'zipcode' =&gt; $_POST["zcode"],'address' =&gt; $_POST["address"]); print_r($person); $personlist = array(); array_push($personlist,$person); print_r($personlist); return $personlist; } </code></pre> <p>When the <code>print_r($personlist);</code> has ran I get the following output:</p> <pre><code> Array ( [0] =&gt; Array ( [firstname] =&gt; 2 [lastname] =&gt; 2 [age] =&gt; 2 [city] =&gt; 2 [zipcode] =&gt; 2 [address] =&gt; 2 ) ) </code></pre> <p>(filled in all textboxes with "2").</p> <p>This is ok at this point, but whenever I fill in another one I get this output:</p> <pre><code>Array ( [0] =&gt; Array ( [firstname] =&gt; 1 [lastname] =&gt; 1 [age] =&gt; 1 [city] =&gt; 1 [zipcode] =&gt; 1 [address] =&gt; 1 ) ) </code></pre> <p>(filled in all textboxes with "1").</p> <p>So instead of creating another person on a new index (<code>index[1]</code>) it replaces <code>index[0]</code> with a new person and deletes the older one. I dont want it do delete it I want to get a list full of people. I think it has to do with the <code>array_push</code> but I am not sure I hope anyone could help me out here.</p> <p><strong>EDIT:</strong></p> <p>Added the index.php:</p> <pre><code>&lt;form action="check.php" method="POST"&gt; &lt;table&gt; &lt;tr&gt;&lt;td&gt;First name&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="fname"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Last name&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="lname"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Age&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="age"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;City&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="city"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Zipcode&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="zcode"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Adress&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="address"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="submit" value="Submit"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p>Added the check.php</p> <pre><code>&lt;?php include("functions.php"); $personlist = array(); $personlist[] = GetSetClearForm(); print_r($personlist); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload