PHP Array comparison implements the method of finding consecutive numbers, PHP array lookup
In this paper, an example of PHP array comparison is implemented to find the sequential number method. Share to everyone for your reference. Specific as follows:
$data = Array () $data []= Array ("n", "n", "+", "24", "+", "+"), $data []= Array ("02", "09", "11", "22", "27", "" ); $data []= Array ("" "," "", "" "", "" ","] "," "," ","]=array "," "", "" "," "", "" "," "" "," "0", $data []=array 2 "," "," "," "," "," "," ","]=array "," $data "(" The "," "", "" "", "" "," ""), $data []=array ("01", "03", "06", "12", "01", "three"), $data []=array ("+", "05", "14", "17", "22");//Determine the table of more than 3 consecutive function Checkall ($sourceArr 2D) {$count = sizeof ($sourceArr 2D); for ($i =0; $i < $count; $i + +) {check_h ($sourceArr 2d[$i], $i);//Find the horizontal direction if ($i >0) {check_v ($SOURCEARR, $i); /Search Vertical Direction check_l ($SOURCEARR, $i);//Search/Direction Check_r ($SOURCEARR, $i);//Search Direction}}}//determine the horizontal direction $h = Array ();// Search results in the horizontal direction function check_h ($arr, $rownum) {//sort ($arr, sort_numeric); Global $h; $flag = false; for ($i =2; $i <6; $i + +) {if ($arr [$i -2]== $arr [$i]-2) {//Because the numbers in the array are not duplicated and ordered so trickery if (! $flag) {$h [$rownum] = Array ($arr [$i-2], $arr [$i-1], $arr [$i]); $flag = true; }else{Array_push ($h [$rownum], $arr [$i]); }}}}//determine the vertical direction $v = array ();//Save the search result in the vertical direction function Check_v ($SOURCEARR, $rownum) {global $v; for ($i =0; $i <6; $i + +) {$val = $sourceArr 2d[$rownum] [$i]; if (In_array ($rownum ... $val, $v)) {continue; } if (In_array ($val, $SOURCEARR 2d[$rownum-1]) && In_array ($val, $SOURCEARR 2d[$rownum +1]) {Array_push ($v, ( $rownum-1) ... $val, $rownum ... $val, ($rownum + 1) ... $val); $tmp = $rownum + 2; while ($tmp < sizeof ($SOURCEARR 2D) && In_array ($val, $SOURCEARR 2d[$tmp]) {Array_push ($v, $tmp ... $val ); $tmp + +; }}}}//judgment/direction = array ();//save/Direction Search result function check_l () {}//Judgment Direction = array ();//Save Direction Search result function Check_r () {}// End definition, start applying checkall ($data), echo//in horizontal direction: Print_r ($h), echo//in vertical direction: Print_r ($v), search in echo//direction: Print_r ($l); echo// Search in the direction: Print_r ($R);
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1039202.html www.bkjia.com true http://www.bkjia.com/PHPjc/1039202.html techarticle PHP Array Comparison to find a continuous number of methods, PHP array to find the example of this article describes the PHP array comparison to achieve the method of finding consecutive numbers. Share to everyone for your reference. Specific as follows: ...