note 120477 deleted from function.array-merge by salathe
| From: | salathe@php.net | Date: | Mon, 06 Sep 2021 22:46:40 +0000 |
| Subject: | note 120477 deleted from function.array-merge by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216909@lists.php.net to get a copy of this message | ||
Note Submitter: rameezsoomro dot pk at live dot com
----
Array merge will return null if any parameter not an array
<?php
$DB_user_result= DB::select()->where()->get(); // return null if not found.
$DB_exists_user_info = ['name'=>'Rameez
Soomro','Location'=>'Karachi, Sindh, Pakistan'];
print_r(array_merge($DB_user_result, $DB_exists_user_info)); //NULL
?>
Here is function for solution of array_merge
function copied from http://sdtuts.com/php-array_merge-function-issue/
<?php
function merge_arrays_obj(){
$func_info = debug_backtrace();
$func_args = $func_info[0]['args'];
$return_array_data = array();
foreach($func_args as $args_index=>$args_data){
if(is_array($args_data) || is_object($args_data)){
$return_array_data = array_merge($return_array_data,$args_data);
}
}
return $return_array_data;
}
?>
Code example how to use it
<?php
$array = array('abc'=>'abcparam');
$null_array = null;
$new_arraydata = array('username'=>'Rameez
Soomro','usersite'=>'http://sdtuts.com');
$new_arrayOBJ = array ( (object) array('obj_DATA' =>
'ABC_OBJ','obj_next_index '=>'ABC_OBJ_NEXT_INDEX') );
$new_array_data = merge_arrays_obj($array,$null_array,$new_arraydata,$new_arrayOBJ);
print_r($new_array_data);
?>