note 119740 deleted from countable.count by cmb

From: Date: Mon, 15 Aug 2016 14:23:39 +0000
Subject: note 119740 deleted from countable.count by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206293@lists.php.net to get a copy of this message
Note Submitter: Tyler ---- 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.

« previous php.notes (#206293) next »