How can I merge PHP arrays?

Mar 12, 2012   //   by phpfreelancer.biz   //   Blog, PHP Tutorial  //  No Comments

Merging two php arrays

$new = array();
    foreach ($array as $arr) {
        $match = false;
        foreach ($array2 as $arr2) {
            if ($arr['id'] == $arr2['id']) {
               $match = true;
               $new[] = array_merge($arr, $arr2);
               break;
            }
        }
        if ( !$match ) $new[] = $arr;
    }

Leave a comment

Share This Post

RSS Wordpress News