|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2003-12-24 18:32 UTC] eru@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 04:00:01 2025 UTC | 
Description: ------------ Is anyone can help me about the code below . Here is I am collecting values according to increment value between number ranges. My first example never hits the end point although the end is in range but second hits the range or third. Why php treats numbers differently or cannot understand the last value is still below end point. Can anyone tell me. Reproduce code: --------------- <?PHP function increment ($start, $end, $increment_val) { $ret_arry = array (); $temp = $start; if ( ($start+$increment_val) <= $end ) { do{ echo " " . $temp . "," ; $temp = $temp + $increment_val; }while ( $temp <= $end ); } else { echo "Can not do This"; } } $start = "1.0"; $end = "1.6"; $increment_val = "0.1"; increment($start, $end, $increment_val); $start = "1.0"; $end = "4.9"; $increment_val = "0.1"; echo "\n"; increment($start, $end, $increment_val); ?> Expected result: ---------------- 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, Actual result: -------------- 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9,