Learn how PHP array initialization works. PHP is powerful and more people are using it. here we will give you a detailed introduction to PHP array initialization. From the beginning of ASP to PHP, I feel that one of the most powerful PHP is the built-in function.
PHPMore and more people are using it. here we will give you a detailed introduction to PHP array initialization. From the beginning of ASP to PHP, I feel that one of the most powerful PHP functions is the rich built-in functions, such as the previously learned PHP date and time functions, all functions related to file reading and writing indicate that PHP is more professional and user-friendly.
At first, I was very excited about the rich functions of PHP functions. as more and more abnormal functions become available, I suddenly think of ASP built-in functions as rare. to complete a special function, user-defined functions are often required. as the number of applications increases, you actually have a set of common function libraries. However, in PHP, these functions have already been standardized and concentrated for direct use of built-in functions. ASP developers have become common PHP users.
However, the existence of these functions and a large number of PHP functions at least shows that PHP is more professional. at the same time, it should be fast and easy to use in our daily PHP program processing, this frees developers from customizing functions for basic functions and detailed functions, and focuses on building more powerful program modules. Therefore, I have strengthened my belief in viewing PHP functions, but I think the PHP function manual should be a portable book in the future development process.
Of course, there is no need to discuss the debate over ASP and PHP advantages and disadvantages. learning and understanding can help you understand the truth. As the saying goes, there are too many PHP functions to prevent forgetting, so I will make a summary and collection every time after reading a class of functions, so I will write a log for convenience.
PHP array initialization and definition
What is an array? An array is a programming structure. it is a variable that stores a group or a series of values. For example, personal identity registration during census, such as name, gender, ethnicity, and birth, can be used as an array. The array created in PHP is defined using the array () structure. PHP array initialization is as follows:
- $people=array('name','sex','nation','brith');
To display the values of each element in an array, we use an index starting from 0. The index number is in square brackets after the variable name. for example:
-
- $people=array('name','sex','nation','birth');
- echo $people[2];
- ?>
The output $ people [2] indicates that nation is displayed (the first index item is counted from 0 ). In addition to numeric index arrays, PHP also supports related arrays. Related arrays are used to replace unintuitive numeric indexes with custom keywords. for example:
-
- $peoples=array('xm'=>'name','xb'=>'sex','mz'=>'nation','cs'=>'birth');
- echo $peoples['cs'];
- ?>
The related array is used to make the output selection intuitive (no pre-calculation of index numbers is required and then output). the defined keywords and values are defined using the "=>" symbol. Based on the two display methods of PHP array elements, you can also create numbers automatically without the need for array () declaration and initialization like variables. For example
- $people[0]='name';
- $people[1]='sex';
- $people[2]='nation';
- $people[3]='brith';
Or
- $peoples['xm']='name';
- $peoples['xb']='sex';
- $peoples['mz']='nation';
- $peoples['cs']='birth';
The size of the array varies dynamically according to the number of added elements.
Http://www.bkjia.com/PHPjc/445771.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445771.htmlTechArticlePHP functions of the powerful, use it more and more people, we here on the PHP array initialization to give you a detailed introduction. From the beginning of ASP to PHP, I feel that one of the powerful PHP is the built-in function...