<?php
$books_sorted = [
["title" => "In Search of Lost Time", 'others' => 'unuseful1'],
["title" => "Don Quixote", 'others' => 'unuseful2'],
["title" => "The Great Gatsby", 'others' => 'unuseful3']
];
$books_available = [
["title" => "Moby Dick", 'others' => 'unuseful4'],
["title" => "In Search of Lost Time", 'others' => 'unuseful5'],
["title" => "The Great Gatsby", 'others' => 'unuseful6'],
["title" => "War and Peace", 'others' => 'unuseful7']
];
var_export(
array_merge(
array_uintersect(
$books_sorted,
$books_available,
fn($a, $b) => $a['title'] <=> $b['title']
),
array_udiff(
$books_available,
$books_sorted,
fn($a, $b) => $a['title'] <=> $b['title']
),
)
);
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array (
0 =>
array (
'title' => 'In Search of Lost Time',
'others' => 'unuseful1',
),
1 =>
array (
'title' => 'The Great Gatsby',
'others' => 'unuseful3',
),
2 =>
array (
'title' => 'Moby Dick',
'others' => 'unuseful4',
),
3 =>
array (
'title' => 'War and Peace',
'others' => 'unuseful7',
),
)
preferences:
42.76 ms | 407 KiB | 5 Q