开发者

Re create new array from two given arrays without duplicate records [closed]

Closed. This question needs details 开发者_开发知识库or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 7 years ago.

Improve this question
Array1
(
    [0] => Array
        (
            [idapartment] => 212
            [guests] => 3
        )

    [1] => Array
        (
            [idapartment] => 1889
            [guests] => 6

        )

)

Array2
(
    [0] => Array
        (
            [id] => 212
            [guests] => 3

        )

    [1] => Array
        (
            [id] => 1549
            [guests] => 3

        )

    [2] => Array
        (
            [id] => 727
            [guests] => 3

        )

    [3] => Array
        (
            [id] => 1889
            [guests] => 3

        )

    [4] => Array
        (
            [id] => 1927
            [guests] => 3

        )

)

Wants third like this array3 :: ie remove ids 212,1889 records

Array3
(
    [0] => Array
        (
            [id] => 1927
            [guests] => 3

        )

    [1] => Array
        (
            [id] => 1549
            [guests] => 6

        )

    [2] => Array
        (
            [id] => 727 
            [guests] => 6

        )

)


foreach($array2 as $child2){
   $count = count($array1);
   $i = 0;
   for($i = 0; $i < $count ; $i++){
      if($array[$i]['idapartment'] == $child['id'])
          unset($array1[$i]);        // removes ids 212,1889 records
   }
}

$array3 = array_merge($array1, $array2);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜