PHP Learning Array-traversing one-dimensional array "2"

Source: Internet
Author: User

In the PHP learning array "1" to learn how to create an array, if PHP learning in the array "1" elements in more words, we access the element is a problem, the following we use the For statement While,foreach to traverse our array:

  

<?PHP/*Range () Prototype: * Array range (mixed $start, mixed $limit [, number $step = 1]) * Parameter Description: * First value of start sequence                。                The limit sequence ends at the value of limit. Step if you give the step value, it will be used as the step value between the units. Step should be positive.         If not specified, step defaults to 1. * Manual Description: * range-Create an array containing the specified range of cells **///the third way to create this is to use a function (range) to create the array$number=Range(0, 10);//creates an array of numbers//print_r ($number);/*results * Array ([0] = 0 [1] = 1 [2] = 2 [3] = 3 [4] = 4 [5] = 5 [6] = 6 [7] = 7 [8] => ; 8 [9] = 9 [ten] = ten)*///We can also specify his stride size for this set of arrays created .$number=Range(0, 10,2);//creates an array of numbers//print_r ($number);/*results * Array ([0] = 0 [1] = 2 [2] = 4 [3] = + 6 [4] = 8 [5] = +)*///You can also create a set of alphabetic arrays:$eng=Range(' A ', ' Z ');//Print_r ($eng);/*Results * * * Array ([0] + a [1] = = b [2] = = c [3] + d [4] + e [5] = f [6] = g [7] + H [8 ] = I [9] = J [Ten] + k [one] = l [n] = m [+] [[+] ~ ~ [] = [+] = [+] = [+] + q [+] => ; r [+] = s [+] = [x] = u [+] = v [+] + w [+] + × [] = y [ +] = z)*/$test=Array(1,2,3,4,5,6,7,8,9,0,10);//For ($i = 0; $i < count ($test), $i + +) {//Echo $test [$i]. ' <br/> ';/}/*Results * 123456789010*///While (!! $a =each ($test)) {//Echo $a [' value ']. ' <br/> ';/}/*result 123456789010*///foreach ($test as $value) {//echo $value. '    <br/> '; // }/*result 123456789010*/    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.