note 129042 added to function.next

From: Date: Mon, 13 Nov 2023 10:10:41 +0000
Subject: note 129042 added to function.next
Groups: php.notes 
Request: Send a blank email to php-notes+get-220998@lists.php.net to get a copy of this message
It is good example how to loop array by current() and next() functions from php key() manual. In my opinion, this particular example would be better placed in current() and next() than key() manuals. <?php $array = array( 'fruit1' => 'apple', 'fruit2' => 'orange', 'fruit3' => 'grape', 'fruit4' => 'apple', 'fruit5' => 'apple'); // this cycle echoes all associative array // key where value equals "apple" reset($array); // prepare array for cycle while ($fruit_name = current($array)) { if ($fruit_name == 'apple') { echo key($array), "\n"; } next($array); } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 212.90.59.36) ---- Manual Page -- https://php.net/manual/en/function.next.php Edit -- https://main.php.net/note/edit/129042 Del: integrated -- https://main.php.net/note/delete/129042/integrated Del: useless -- https://main.php.net/note/delete/129042/useless Del: bad code -- https://main.php.net/note/delete/129042/bad+code Del: spam -- https://main.php.net/note/delete/129042/spam Del: non-english -- https://main.php.net/note/delete/129042/non-english Del: in docs -- https://main.php.net/note/delete/129042/in+docs Del: other reasons-- https://main.php.net/note/delete/129042 Reject -- https://main.php.net/note/reject/129042 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220998) next »