Php
5000~7000
2000~6000
8000~9000
4000~8500
5000~7000
How are these random sets of data in PHP more effective in judging if there are duplicates?
Expectations are
2000~4000
4000~5000
5000~6000
6000~7000
7000~8500
8500~9000
Reply to discussion (solution)
This post was last edited by xuzuning on 2013-10-09 09:00:13
$a = Array (array (7000), array (6000), Array (8000, 9000), Array (4000, 8500), Array (, 7000), (); $r = Arra Y (), foreach ($a as $v) {$r [] = $v [0]; $r [] = $v [1];} $r = Array_unique ($r); sort ($r); $a = array (); for ($i =0; $i
Array
(
[0] = = Array
(
[0] = 2000
[1] = 4000
)
[1] = = Array
(
[0] = 4000
[1] = 5000
)
[2] = = Array
(
[0] = 5000
[1] = 6000
)
[3] = = Array
(
[0] = 6000
[1] = 7000
)
[4] = = Array
(
[0] = 7000
[1] = 8000
)
[5] = = Array
(
[0] = 8000
[1] = 8500
)
[6] = = Array
(
[0] = 8500
[1] = 9000
)
)
Really very quickly, thank you moderator.
I want to get these groups of data whether there are duplicate flags,
There is a repeat return of false,
No repetition returns True,
You do not need to generate a new, non-repeating array.
Array
Array (5000, 7000),
Array (2000, 6000),
Array (8000, 9000),
Array (4000, 8500),
Array (5000, 7000),
);
The following conditions are not duplicated and expected to return true
Array
Array (2000, 3000),
Array (3000, 4000),
Array (4000, 5000)
);
"Green", "B" and "Brown", "c" = "blue", "Red"); $array 2 = Array ("A" = "green", "b" = "yellow", "blue", "red") ; $result _array = Array_intersect_assoc ($array 1, $array 2);p Rint_r ($result _array);? >
Determine if the $result_array is empty
"Green", "B" and "Brown", "c" = "blue", "Red"); $array 2 = Array ("A" = "green", "b" = "yellow", "blue", "red") ; $result _array = Array_intersect_assoc ($array 1, $array 2);p Rint_r ($result _array);? >
Determine if the $result_array is empty
Array_intersect_assoc
This two-dimensional array cannot be judged.
And this is a situation that does not belong to the intersection range.
Array
Array (2000, 3000),
Array (3000, 4000),
Array (4000, 5000)
);
You're not going to be a bit flexible?
If the original array is duplicated, then the resulting non-repeating array must be larger than the original array
Find out the specific scope according to the moderator's program
Alas, it is easier to simply ask for True,false:
Comparing the minimum value of any two items to the maximum of the other is the same, once there is an intersection->break loop, if until the end of the loop, there is no intersection
You're not going to be a bit flexible?
If the original array is duplicated, then the resulting non-repeating array must be larger than the original array
Thank you moderator.
Re-order the new non-repeating array,
If the number of non-repeating array elements changes, there is a overlap between the original array, right?
The flag is not likely to be correctly judged in either of the following cases
$a = Array (
Array (5000, 7000),
Array (6000, 8200),
Array (8000, 9000)
);
$a = Array (
Array (5000, 5500),
Array (6000, 6500),
Array (8000, 8500)
);
There is no more effective way.
Only need to distinguish whether it is included, can be written as function
or follow the beginning of the idea
$a = Array (7000, array (6000), Array ( 8000, 9000), Array ( 4000, 8500) , Array ( 7000), Var_dump (foo ($a)); BOOL (false) $a = array ( array (7000), array ( 6000, 8200), Array (8000, 9000)), Var_dump (foo ($a)); BOOL (false) $a = array ( array (5500), Array ( 6000, 6500), Array (8000, 8500)), Var_dump (foo ($a)); BOOL (true) function foo ($a) { $r = Array_unique (Call_user_func_array (' Array_merge ', $a)); Sort ($r); foreach ($a as $v) { if (array_search ($v [0], $r)! = Array_search ($v [1], $r)-1) return false; } return true;}
Only need to distinguish whether it is included, can be written as function
or follow the beginning of the idea
$a = Array (7000, array (6000), Array ( 8000, 9000), Array ( 4000, 8500) , Array ( 7000), Var_dump (foo ($a)); BOOL (false) $a = array ( array (7000), array ( 6000, 8200), Array (8000, 9000)), Var_dump (foo ($a)); BOOL (false) $a = array ( array (5500), Array ( 6000, 6500), Array (8000, 8500)), Var_dump (foo ($a)); BOOL (true) function foo ($a) { $r = Array_unique (Call_user_func_array (' Array_merge ', $a)); Sort ($r); foreach ($a as $v) { if (array_search ($v [0], $r)! = Array_search ($v [1], $r)-1) return false; } return true;}
This is a wonderful remark. Thank you, moderator.
Array_search ($v [0], $r)! = Array_search ($v [1], $r)-1
The above code I'll
Array
Array (2000, 3000),
Array (3000, 4000),
Array (4000, 5000)
);
The situation is considered and you can do it.
Thank you so much. M (_ _) m