Last active
May 19, 2020 03:34
-
-
Save kingjmaningo/777401fd153d754887a12d6bd2a7b345 to your computer and use it in GitHub Desktop.
Simple merge array (PHP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$new_data = array( | |
'id' => 4, | |
'name' => 'Magic', | |
'email' => 'user_email_4', | |
'birth_date' => '10-11-2019' | |
); | |
$current_data = array ( | |
array( | |
'id' => 1, | |
'name' => 'Kobe', | |
'email' => 'user_email_1', | |
'birth_date' => '10-22-2019' ), | |
array( | |
'id' => 2, | |
'name' => 'Lebron', | |
'email' => 'user_email_2', | |
'birth_date' => '11-01-2019' ), | |
array( | |
'id' => 3, | |
'name' => 'Mike', | |
'email' => 'user_email_3', | |
'birth_date' => '10-18-2019' ) | |
); | |
// Make sure current data has value | |
if (!empty($current_data)) { | |
$updated_data = array_merge( $current_data, array ($new_data)); | |
echo '<pre>'; | |
print_r($updated_data); | |
echo '</pre>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment