The method for PHP to output array elements

time:13-03-25 forum:PHP tools and code
  Reprinted from http://infinity-love-cl.blog.163.com/blog/static/10311054520096552153340/

often used to access the values of arrays in actual development. It is very cumbersome if each element is indexed by array index. In
PHP, you can quickly access array elements through various loops. This section introduces the common for and foreach.
uses an for loop statement to output array elements for an array that is indexed in an integer order, which can be accessed by an array element,
[code]
$ms_office = array (
'word',
'excel',
echo $ms_office.#91; $i.#93;
echo.Quot; The grammatical structure of a ring statement is shown as follows.
[code]foreach ($array as $some_var)
{
statement
}[/code]
foreach and as are the keyword of the extension. The meaning of this grammatical structure is that, in order, every time a meta
element in the array $array is stored in the variable $some_var, the statement statement is executed, then the next element is taken to execute the statement statement, and then, in turn, until
all elements are taken. Like for loop statements, statement can be a single statement or a statement block. Code 4-2 can be
in the form of code 4-3, and the result of output is exactly the same as that on the code.

use the foreach loop to get array elements
[code]$ms_office = array (
'word',
'excel',
'outlook'). This code sequentially stores each element of the array in variable $software and prints it out. Foreach loop can not only obtain array elements, but also obtain index
[code]$ms_office = array (
'wd'=.gt;'word',
'ec'=.gt;'excel',
'ol'=.gt). .quot;
.quot;;
echo.Quot;
.quot;
}
?.gt; [/code]
in this code, each index loop assigns an index of the array to the variable / variable, and assigns its corresponding value to the variable.

prev:Basic concept of character coding next:The Spring Festival in Ji'nan is publici...
post comment
Notice



approved   A small set of fingers can adjust th...   In the mountains, after 80 years hai...   The General Administration of food a...   She turned the "abnormal" into a win...   Primary school is now "adult corrupt...
rand   Using Json to realize data exchange ...   PHP verification code landing check   Install.php simple production   Wan net interview PHP written test   PHP automatically identifies links i...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com