Analysis of PHP block query implementation method

Source: Internet
Author: User
This article mainly introduces the PHP block query implementation method, combined with the example form simple analysis of PHP block query concept, principle, implementation and use of operational skills, the need for friends can refer to the next

In this paper, the implementation method of PHP block query is described. Share to everyone for your reference, as follows:

A block query is a query method between a sequential query and a binary query.

In fact, binary query is each binary block query, then block query is to divide the array into chunks, and then each chunk query method.

In this example, the array is already numbered, and the order is queried after the blocks have been sorted.

PHP Code:

<?php$arr = Array (1,2,3,4,5,6,7,8,9,10);p Rint_r (Blocksearch (3,1, $arr)), function Blocksearch ($block, $key, $arr) {  $length = count ($arr);  $position = 0;  while ($length >= $position) {///array elements are over, end loop    for ($i =1; $i <= $block; $i + +) {//cycles are the size of the defined block      if ($arr [$ Position] = = $key) {//Found element        return ' value: '. $arr [$position]. '; Position: '. $position;      }      $position ++;//per comparison, position is moved back once    }  }}?>

Operation Result:

value:1;position:0

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.