Home  >  Article  >  Backend Development  >  Introduction to how to create an array in php

Introduction to how to create an array in php

WBOY
WBOYOriginal
2016-07-25 09:04:481329browse
PHP does not need to specify the size of an array when creating it. Since PHP is a loosely typed language, you don't even need to declare an array before using it. Although there are no strict restrictions, PHP still provides formal and informal array declaration methods.

php does not need to specify the size of an array when creating it. Since PHP is a loosely typed language, you don't even need to declare an array before using it. Although there are no strict restrictions, PHP still provides formal and informal array declaration methods.

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

Method 1: Create an array directly using the assignment method Next we create an array containing the script school name: Introduction to how to create an array in php The lower group of the array in PHP also starts from 0. To output an array, write directly like this: Introduction to how to create an array in php If you want to modify the value of the array, just assign the value directly to the array at the current index, for example: Introduction to how to create an array in php If the index value of the array is a numeric index and is increasing, the index value can also be omitted when creating: Introduction to how to create an array in php Creating associative arrays this way is also very simple, but you must always use keys. Consider the following example: Introduction to how to create an array in php Finally, let’s talk about another way to create a php array, which is to use the array() function. The array() function accepts 0 or more elements as input and returns an array containing these input elements. Its form is as follows: array array([item1 [,item2 ...[,itemN]]])

For example: Introduction to how to create an array in php Okay, that’s it for introducing the method of creating arrays in php. I hope it can help you. Programmer's home, dedicated to you.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn