Create an array with the range function

Source: Internet
Author: User
This article introduces the content is about using the range function to create an array, has a certain reference value, now share to everyone, the need for friends can refer to

Array Traversal language


--Quickly create an array
--range (1,5)


What does this range function mean? Who is the key? Who is the value? Range is a quick-create array


Function. The functions provided by PHP to quickly create an array include range (), explode (),
Array_combine (), Array_fill (), and Array_pad (). The rest of the functions should be ignored.


Yes. Focus on the range () function.


Syntax format, Arrge range (mixed start,mixed end)
function function: Quickly create a numeric array or a character array from start to end range.
Note that if start>end, the sequence will be descending from start to end.
Here, let's give an example,

<?php$numbers = range (1,5);//An array called numbers with five values in it. Array (1,2,3,4,5) Print_r ($numbers);/* output, array ([0]=>1 [1]=>2] [2]=>3 [3]=>4] * Front is key, followed by value 4]=>5 What if it's a string? It's not a number. $chars1 = Range (' A ', ' d ');//chars is a character. The start sequence is a, the end sequence is Dprint_r ($chars 1);/* The value inside the output array. *array ([0]=>a [1]=>b] [2]=>c [3]=>d] */?>

Summarize, create an array, and then iterate over the array. The limit can only be a regular sequence. If nothing


Law, then helpless.

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.