note 120477 added to function.array-merge
| From: | rameezsoomro dot pk at live dot com | Date: | Tue, 17 Jan 2017 17:17:50 +0000 |
| Subject: | note 120477 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-208744@lists.php.net to get a copy of this message | ||
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);
?>
----
Server IP: 72.52.91.14
Probable Submitter: 27.96.93.94
----
Manual Page -- http://php.net/manual/en/function.array-merge.php
Edit -- https://master.php.net/note/edit/120477
Del: integrated -- https://master.php.net/note/delete/120477/integrated
Del: useless -- https://master.php.net/note/delete/120477/useless
Del: bad code -- https://master.php.net/note/delete/120477/bad+code
Del: spam -- https://master.php.net/note/delete/120477/spam
Del: non-english -- https://master.php.net/note/delete/120477/non-english
Del: in docs -- https://master.php.net/note/delete/120477/in+docs
Del: other reasons-- https://master.php.net/note/delete/120477
Reject -- https://master.php.net/note/reject/120477
Search -- https://master.php.net/manage/user-notes.php