PHP array pointer study notes (1)

WBOY
Release: 2016-07-28 08:29:42
Original
1017 people have browsed it

There is such a problem. In an array queue, the array length is fixed. When inserting elements into the input, after the maximum length is exceeded, the array automatically starts overwriting and filling.

At this time, the entire array forms a ring. As shown below.​​​​When the array is less than the specified length, add elements directly

 php数组指针学习笔记(一)                                                                                                       use using each to take out the element of the current pointer and move the pointer down

List ($ k, $ v) = EACH ($ test_array);


// Generally use the mold taking algorithm, obtain the key to be covered, and then directly overwrite


$ k = $ k % 12;
$test_array[$k] = $value;

}

}
push_array(0,$test_array);

push_array(1,$test_array);

push_array(2,$test_array);
push_array(3,$test_array);

push_array(4,$test_array);

push_array(5,$test_array);
push_array(6,$test_array);

push_array(7,$test_array);

push_array(8,$test_array);

push_array(9, $test_array);

push_array(10,$test_array);
push_array(11,$test_array);

push_array(12,$test_array);

push_array(13,$test_array);
push_array(14,$test_array);
push_array(15,$test_array);
push_array(16,$test_array);
push_array(17,$test_array);
push_array(18,$test_array);
push_array(19,$test_array);
push_array(20,$ test_array);
push_array(21,$test_array);
push_array(22,$test_array);
push_array(23,$test_array);
push_array(24,$test_array);
var_dump($test_array);exit;

Test results:

<span>array(12) {
  [0]=>
  int(24)
  [1]=>
  int(13)
  [2]=>
  int(14)
  [3]=>
  int(15)
  [4]=>
  int(16)
  [5]=>
  int(17)
  [6]=>
  int(18)
  [7]=>
  int(19)
  [8]=>
  int(20)
  [9]=>
  int(21)
  [10]=>
  int(22)
  [11]=>
  int(23)
}</span>
Copy after login


In addition to each, the following array pointer function also works well


current() - returns the value of the current element in the array

end() - points the internal pointer to the last element in the array element, and output

next() - Point the internal pointer to the next element in the array, and output

prev() - Point the internal pointer to the previous element in the array, and output

reset() - Set the internal The pointer points to the first element in the array and outputs

The above introduces the PHP array pointer study notes (1), including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!