How PHP array initialization works-PHP Tutorial

Source: Internet
Author: User
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:

 
 
  1. $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:

 
 
  1. $people=array('name','sex','nation','birth');
  2. echo $people[2];
  3. ?>

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:

 
 
  1. $peoples=array('xm'=>'name','xb'=>'sex','mz'=>'nation','cs'=>'birth');
  2. echo $peoples['cs'];
  3. ?>

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

 
 
  1. $people[0]='name';
  2. $people[1]='sex';
  3. $people[2]='nation';
  4. $people[3]='brith';

Or

 
 
  1. $peoples['xm']='name';
  2. $peoples['xb']='sex';
  3. $peoples['mz']='nation';
  4. $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...

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.