Home > Article > Backend Development > Introduction to how to create an array in php
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: The lower group of the array in PHP also starts from 0. To output an array, write directly like this: If you want to modify the value of the array, just assign the value directly to the array at the current index, for example: If the index value of the array is a numeric index and is increasing, the index value can also be omitted when creating: Creating associative arrays this way is also very simple, but you must always use keys. Consider the following example: 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: 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. |