Your source array is wrong. You need to have something like this:
$array1 = array('name' => '', 'email' => '', 'phone' => '');
And if you want to extend with the empty values, you can use:
$array2 = array('name' => 'John', 'phone' => '55-555-555');
The final array can be made by using array_merge:
Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.
$array2 = array_merge($array1, $array2);
You will get this as output:
array('name' => 'John', 'email' => '', 'phone' => '55-555-555');
Full Code
$array1 = array('name' => '', 'email' => '', 'phone' => '');
$array2 = array('name' => 'John', 'phone' => '55-555-555');
$array2 = array_merge($array1, $array2);
var_export($array2);
Output
array (
'name' => 'John',
'email' => '',
'phone' => '55-555-555',
)
Demo: http://ideone.com/7zlab7
Better Explanation
// Have a base array that has all the required fields.
$baseArr = array('name', 'email', 'phone', 'password');
// Get your array with the initial values, (without a few fields).
$myArray = array('name' => 'david', 'email' => '[email protected]', 'phone'=> '123456789');
// Now make a new array on the fly with array_fill_keys using the baseArr
// and merge with the original user array.
$myArray = array_merge(array_fill_keys($baseArr, ''), $myArray);
// The resultant array will have all the fields.
print_r($myArray);
Output
Array
(
[name] => david
[email] => [email protected]
[phone] => 123456789
[password] =>
)
Demo: http://ideone.com/XLCMN9
<table>?