Arrays in php

Good afternoon.

There is code that puts values ‚Äč‚Äčinto an array, but with such an organization, the array is overwritten and only the latest data is entered into it.
Question: how do I need to change the code for the script to work?

$input = $dom->find('input[id="reg_username"]');
$fieldname = array('login' => $input[0]->name);
$input = $dom->find('input[id="reg_email"]');
$fieldname = array('email' => $input[0]->name);
var_dump($fieldname);

Output:

array(1) { [’email’]=> string(32)
[email protected]” }

Thanks in advance!


Answer 1, authority 100%

You can do this:

$fieldname = array();
$input = $dom->find('input[id="reg_username"]');
$fieldname['login'] = $input[0]->name;
$input = $dom->find('input[id="reg_email"]');
$fieldname['email'] = $input[0]->name;