note 119740 added to countable.count

From: Date: Mon, 15 Aug 2016 14:07:45 +0000
Subject: note 119740 added to countable.count
Groups: php.notes 
Request: Send a blank email to php-notes+get-206292@lists.php.net to get a copy of this message
Quick note when using count with for-loop and arrays. Count starts at 1, unlike how arrays start at 0. Testing - var_dump(count(["hi"])); displayed 1 So, yea be sure to handle this before using it like the following: $array = ["hi", "hello", "hey"]; for($index=0; $index<count($array); $index++){ $array[$index]=/*do something here*/; } As, that for-loop will really look like: for($index=0; $index<3; $index){ //Which also means, the following line will occur at some point $array[3]=/*do something here*/; } Of course, this would throw some type of out-of-bounds exception. ---- Server IP: 72.52.91.14 Probable Submitter: 142.166.8.5 ---- Manual Page -- http://php.net/manual/en/countable.count.php Edit -- https://master.php.net/note/edit/119740 Del: integrated -- https://master.php.net/note/delete/119740/integrated Del: useless -- https://master.php.net/note/delete/119740/useless Del: bad code -- https://master.php.net/note/delete/119740/bad+code Del: spam -- https://master.php.net/note/delete/119740/spam Del: non-english -- https://master.php.net/note/delete/119740/non-english Del: in docs -- https://master.php.net/note/delete/119740/in+docs Del: other reasons-- https://master.php.net/note/delete/119740 Reject -- https://master.php.net/note/reject/119740 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206292) next »