Home  >  Article  >  Backend Development  >  PHP arrays and conditions, loop statement learning_PHP tutorial

PHP arrays and conditions, loop statement learning_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:14:251095browse

1. Array

Example 1:

1). Rendering preview:

PHP arrays and conditions, loop statement learning_PHP tutorial

2).Code screenshot:

The following is a two-dimensional array, which is often used in practice.

PHP arrays and conditions, loop statement learning_PHP tutorial

$mess = array('title'=>'Message title 1','content'=>'Content','ctime'=>'2012-1-1 12:34:23'); //Associative array

//Statement to traverse the array

//The first type
foreach($mess as $v){ //foreach can traverse associative arrays; while the for loop can only traverse enumeration arrays, not associative arrays.
//$v It is the value that receives the array element. The number of iterations of the loop body is determined by the array element
echo $v.'
';
}

//The second type
foreach($mess as $k=>$v){
//$k is used to receive the key name or index corresponding to the data element, $v is to receive the array element The value of
echo $k.'-----'.$v.'
';

Example 2:

1). Rendering preview:

PHP arrays and conditions, loop statement learning_PHP tutorial

2).Code screenshot:

PHP arrays and conditions, loop statement learning_PHP tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326316.htmlTechArticle1. Array example 1: 1). Rendering preview: 2). Code screenshot: The following is a two-dimensional Array, actually used more often. $mess = array('title'='Message title 1','content'='content','ctime'='2012-1...
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