I have a unordered array of numbers:
$ar1 = [101,4,320,1,2,3,45,46];
and i want to extract longest sequence of numbers in that array and put them in second array? I have tried with usort and I get this:
Array(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 45
[5] => 46
[6] => 101
[7] => 320
[8] => 321
[9] => 323)
but how to extract just longest sequence (witch in this case is 1,2,3,4) and put in another array?
UPDATE: Here is a code:
function sub($a,$b)
{
if ($a == $b)
{
return 0;
}
return ($a<$b)? -1:1;
}
$ar1 = ["101","4","320","321","323","1","3","2","45","46"];
$ar2 = [];
usort($ar1,"sub");
print_r($ar1);
so i want to populate $ar2 with longest sequence in array...