Php array comparison to find the continuous number of methods, php array lookup _ PHP Tutorial

Source: Internet
Author: User
Php array comparison method to find the continuous number, php array search. The php array comparison method is used to find the continuous number. The php array search example in this article describes how to compare the php array to find the continuous number. Share it with you for your reference. The details are as follows: php array comparison method to find the continuous number, php array search

This example describes how to compare php arrays to find continuous numbers. Share it with you for your reference. The details are as follows:

$ Data = array (); $ data [] = array ("01", "02", "18", "29", "31", "32 "); $ data [] = array ("02", "09", "11", "22", "24", "27 "); $ data [] = array ("07", "16", "26", "27", "29", "31 "); $ data [] = array ("04", "05", "07", "10", "13", "25 "); $ data [] = array ("02", "04", "05", "08", "19", "22 "); $ data [] = array ("03", "04", "15", "25", "26", "30 "); $ data [] = array ("01", "03", "06", "12", "16", "32 "); $ data [] = array ("01", "05 "," 14 "," 17 "," 22 "); // identifies more than three consecutive functions in the table checkAll ($ sourceArr2D) {$ count = sizeof ($ sourceArr2D); for ($ I = 0; $ I <$ count; $ I ++) {check_h ($ sourceArr2D [$ I], $ I); // find the horizontal direction if ($ I> 0) {check_v ($ sourceArr2D, $ I); // find the vertical direction check_l ($ sourceArr2D, $ I ); // find/direction check_r ($ sourceArr2D, $ I); // find direction }}// judge the horizontal direction $ h = array (); // Save the search result 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) {// 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 function check_v ($ sourceArr2D, $ rownum) {global $ v; for ($ I = 0; $ I <6; $ I ++) {$ val = $ sourceArr2D [$ rownum] [$ I]; if (in_array ($ rownum... $ val, $ v) {continue;} if (in_array ($ val, $ sourceArr2D [$ rownum-1]) & in_array ($ val, $ sourceArr2D [$ rownum + 1]) {array_push ($ v, ($ rownum-1 )... $ val, $ rownum... $ val, ($ rownum + 1 )... $ val); $ tmp = $ rownum + 2; while ($ tmp <sizeof ($ sourceArr2D) & in_array ($ val, $ sourceArr2D [$ tmp]) {array_push ($ v, $ tmp... $ val); $ tmp ++ ;}}/// judge/direction $ l = array (); // Save/search result function check_l () in the direction () {}// judgment direction $ r = array (); // Save the search result function check_r () {}// end the definition and start to apply checkAll ($ data ); echo // horizontal direction: print_r ($ h); echo // Vertical direction: print_r ($ v); echo // direction: print_r ($ l); echo // search in the direction: print_r ($ r );

I hope this article will help you with php programming.

Examples in this article describes how to find continuous numbers by comparing php arrays. Share it with you for your reference. Details :...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.