note 78791 added to function.array

From: Date: Sun, 28 Oct 2007 00:39:29 +0000
Subject: note 78791 added to function.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-131784@lists.php.net to get a copy of this message
I wanted to put a large range of numbers into an array but it seems to me that the array function don't have that kind of ability for me to put in a range of numbers without having to list down every single number. Here's my solution: <?php function arr_range($r1,$r2){ // the end range is smaller than the start range // switch around if($r2 < $r1){ $t = $r1; $r1 = $r2; $r2 = $t; unset($t); } $return_val = array(); $i = 0; // for each value of the range // add the value into the temparory array for($i = $r1;$i<=$r2;$i++){ $return_val[] = $i; } // return the values in array form return $return_val; } // example usages $values = arr_range(100,6000); $values = arr_range(1996,2010); $values = arr_range(50,25); // it works $values = arr_range(-64,1024); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 218.186.10.12 (proxied: 222.165.25.127) ---- Manual Page -- http://www.php.net/manual/en/function.array.php Edit -- https://master.php.net/note/edit/78791 Del: integrated -- https://master.php.net/note/delete/78791/integrated Del: useless -- https://master.php.net/note/delete/78791/useless Del: bad code -- https://master.php.net/note/delete/78791/bad+code Del: spam -- https://master.php.net/note/delete/78791/spam Del: non-english -- https://master.php.net/note/delete/78791/non-english Del: in docs -- https://master.php.net/note/delete/78791/in+docs Del: other reasons-- https://master.php.net/note/delete/78791 Reject -- https://master.php.net/note/reject/78791 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131784) next »