Ask how to ask if x contains y and x is sorted by y. In fact, it requires that x contains y and x is sorted by y to compare the arrays x and y. if x is longer than y, append the extra keys in array x to the end of array y, for example, $ x & nbsp; array (0 & gt; a, & nbsp; 1 & gt; B, & nbsp; 2 & gt; c, & nbsp; 3 & gt; d, & nbsp; 4 & gt; e); ask if x contains y and x is sorted by y
In fact, it requires that x contains y and x is sorted by y.
Compare the arrays x and y,
If x is longer than y, the extra keys in array x are appended to the end of array y.
For example:
$ X = array (0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D ', 4 => 'e ');
$ Y = array (2 => 'C', 4 => 'e', 0 => 'A ');
The result is array (2 => 'C', 4 => 'e', 0 => 'A', 1 => 'B ', 3 => 'd ');
If x is less than y, delete the extra keys in the y array first.
$ X = array (0 => 'A', 1 => 'B ');
$ Y = array (2 => 'C', 4 => 'e', 0 => 'A ');
The result is array (0 => 'A', 1 => 'B ');
Share To: 'A ',? 1 => 'B',... 'data-pics = ''>
------ Solution --------------------
Question 1
$x = array(0=>'a', 1=>'b', 2=>'c', 3=>'d', 4=>'e');
$y = array(2=>'c', 4=>'e', 0=>'a');
$c = array_diff_key($x, $y);
$z = $y + $c;
print_r($z);
Array
(
[2] => c
[4] => e
[0] => a
[1] => b
[3] => d
)
The second question is not clear
$ X = array (0 => 'A', 1 => 'B ');
$ Y = array (2 => 'C', 4 => 'e', 0 => 'A ');
The result is array (0 => 'A', 1 => 'B'). // is this $ x?
I don't see any relationship with $ y.