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