Comunitatea PHP Romania
 

 
range

range

(PHP 3>= 3.0.8, PHP 4 , PHP 5)

range --  Create an array containing a range of elements

Description

array range ( mixed low, mixed high)

range() returns an array of elements from low to high, inclusive. If low > high, the sequence will be from high to low.

Exemplu 1. range() examples

foreach(range(0, 9) as $number) {
    echo $number;
}
foreach(range('a', 'z') as $letter) {
    echo $letter;
}
foreach(range('z', 'a') as $letter) {
    echo $letter;
}

Notã: Prior to version 4.1.0 the range() function only generated incrementing integer arrays. Support for character sequences and decrementing arrays was added in 4.1.0.

Exemplu 2. Simulating decrementing ranges and character sequences

# array_reverse can be used to flip the order of a range
foreach(array_reverse(range(0,9)) as $number) {
    echo $number;
}

# array_map() can be used to turn integers into characters using chr()
foreach(array_map('chr', range(ord('a'),ord('z'))) as $character) {
    echo $character;
}

See shuffle() for another example of its use.

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink Broadband Specials | Mortgages | Personal Loans | Arcade Games | Web Advertising
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis