两个相似数组的交集

我有两个数组,第一个是第二个的排序版本(由用户排序),但第二个可以比第一个短或长。例如:


$books_sorted = array(

     0 => array(

        "title" => "In Search of Lost Time"

     ),

     1 => array(

        "title" => "Don Quixote"

     ),

     2 => array(

        "title" => "The Great Gatsby"

     )

);


$books_available = array(

      0 => array(

         "title" => "Moby Dick"

      ),

      1 => array(

         "title" => "In Search of Lost Time"

      ),

      2 => array(

         "title" => "The Great Gatsby"

      ),

      3 => array(

         "title" => "War and Peace"

      )

);

我需要第三个数组,它尊重用户设置的顺序,但从第二个数组中删除丢失的书籍,并在其末尾添加第二个数组中的所有新书籍。埃斯。


// "Don Quixote" is not available anymore -> needs to be removed

// "War and Peace" and "Moby Dick" are available -> need to be added both at the end


$books_third_array = array(

     0 => array(

        "title" => "In Search of Lost Time"

     ),

     1 => array(

        "title" => "The Great Gatsby"

     ),

     2 => array(

        "title" => "Moby Dick"

     ),

     3 => array(

        "title" => "War and Peace"

     )    

);

我只放了“title”键,因为还有其他键,但我认为它们对这个例子没有用。任何帮助表示赞赏,谢谢。


Helenr
浏览 116回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP