How to create an array in php

Source: Internet
Author: User
How to create an array in php
Php does not need to specify its size when creating an array. Since php is a loose language, you do not even need to declare it before using arrays. Although there are no strict restrictions, php still provides formal and informal array declaration methods.

Php does not need to specify its size when creating an array. Since php is a loose language, you do not even need to declare it before using arrays. Although there are no strict restrictions, php still provides formal and informal array declaration methods.

This article will introduce two methods for creating php arrays for your reference.

Method 1: directly create an array using the value assignment method. below we will create an array containing the name of the script School: The next group of arrays in php also starts from 0. Output array: If you want to modify the value of an array, you can directly assign a value to the array of the current index. for example, if the index value of an array is a numerical index and increases progressively, you can also omit the index value during creation: it is very easy to create an associated array in this way, but you must always use the key. Let's take a look at the example below: Finally, let's talk about another method to create a php array, that is, using the array () function. The array () function accepts 0 or more elements as input, and returns an array containing these input elements. The format is as follows: array ([item1 [, item2... [, itemN])

For example: Well, the method for creating an array in php is described here. I hope it will help you. Programmer's house, dedicated to you.

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.