Chaitanya Lakshmi
  • About Me
  • Job Duties
  • Knowledge Blog
  • Applications
  • Contact Us
    • Linked In
    • Facebook
  • About Me
  • Job Duties
  • Knowledge Blog
  • Applications
  • Contact Us
    • Linked In
    • Facebook

How can I create an array of numbers easily?

4/10/2012

0 Comments

 
If you want to create an array of consecutive numbers in PHP, then you can do it the long hand way...

<?php 
$myarray = array(1,2,3,4,5,6,7); 
?> 

Or you can do it the easy way, using the range function, which you simply pass the first and last value in the consecutive range. So this is equivalent to the above code:

<?php 
$myarray = range(1,7); 
?> 

... and when you want an array containing the numbers 1 to a 1,000 - then you'll be glad you learned about this function!
0 Comments



Leave a Reply.

    Archives

    April 2012
    March 2012
    February 2012

    Categor

    All
    Ajax
    Api
    Cross Site Scripting
    Css
    Curl
    Design Patterns
    Drupal
    Exception Handling
    Htaccess
    Html
    Javascript
    Jquery
    Json
    Linux
    Mysql
    Oops
    Php
    Regular Expressions
    Web 2.0
    Webservices
    Wordpress
    Xhtml

    RSS Feed

Powered by Create your own unique website with customizable templates.