Array comparison, find continuous instances-PHP source code

Source: Internet
Author: User
Array comparison, find the php code of the continuous number of instances

$ 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"); // you can specify more than three consecutive values in the table. http://blog.qita.infunction CheckAll ($ sourceArr2D) {$ count = sizeof ($ sourceArr2D); for ($ I = 0; $ i0) {check_v ($ sourceArr2D, $ I ); // find the vertical direction check_l ($ sourceArr2D, $ I); // find/direction check_r ($ sourceArr2D, $ I ); // query direction }}// determine 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 ); search in the echo horizontal direction:; print_r ($ h); search in the echo vertical direction:; print_r ($ v); search in the echo/direction :; print_r ($ l); search in the echo direction:; print_r ($ r );

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.