In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "what is php iterator". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Php iterator is a PHP design pattern, which refers to the interface of one's own external iterator or class that can be iterated internally; the iterator pattern can traverse the internal elements of an aggregate object without knowing the internal implementation.
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
What does php iterator mean?
PHP iterator mode
Iterator: the class inherits PHP's Iterator interface and operates in batches.
1. The iterator pattern traverses the internal elements of an aggregate object without knowing the internal implementation.
two。 Compared to the traditional programming mode, the iterator pattern can hide the actions required to traverse elements.
Interface Iterator
Current () returns the current element
Key () returns the key of the current element
Next () moves forward to the next element
Rewind () returns to the first element of the iterator
Class AllUser implements\ Iterator {protected $index = 0; protected $data = []; public function _ _ construct () {$link = mysqli_connect ('192.168.0.91,' root', '123,' xxx'); $rec = mysqli_query ($link, 'select id from doc_admin'); $this- > data = mysqli_fetch_all ($rec, MYSQLI_ASSOC) } / / 1 reset iterator public function rewind () {$this- > index = 0;} xxx / / 2 verify whether the iterator has data public function valid () {return $this- > index
< count($this->Data);} / / 3 get current content public function current () {$id = $this- > data [$this- > index]; return User::find ($id);} / / 4 move key to the next public function next () {return $this- > index++;} / / 5 iterator location key public function key () {return $this- > index }} / / implement iterative traversal of user table $users = new AllUser (); / / real-time modification of foreach ($users as $user) {$user- > add_time = time (); $user- > save ();} "what is an php iterator" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.