Detailed explanation of PHP assignment to array (two-dimensional array assignment)_PHP tutorial

WBOY
Release: 2016-07-13 17:16:18
Original
1033 people have browsed it

Array assignment in PHP is very simple. If it is a one-dimensional array assignment, it is simpler than a two-dimensional array or a multi-dimensional array. Now I will introduce to you various examples of array assignment. Friends who need to know can refer to it.

What about PHP array assignment? As follows:

Example 1, one-dimensional array assignment

The code is as follows
 代码如下 复制代码

$My_array=array(); 
$My_array[]=”www”  
$My_array[]=”helpphp”;  
$My_array[]=”cn”;

Copy code


$My_array=array();
 代码如下 复制代码

unset($My_array[0];
unset($My_array); 

$My_array[]=”www”

$My_array[]=”helpphp”;
$My_array[]=”cn”;

 代码如下 复制代码

$data_array=array($total,2);//其中$datarows为查询得到的记录数 
$data_array[$i][2]=$Area;//提示错误:Cannot use a scalar value as an array 


 代码如下 复制代码

$i=0;
 while($result=$db->fetch_array($query))
 {  $Area=$result["Area"];
 $data_array[$i][2]=$Area; //出错! 
$i=$i+1;    
}  

Destroy array
The code is as follows
Copy code

unset($My_array[0];

unset($My_array); Example 2, two-dimensional array assignment
The code is as follows Copy code
$data_array=array($total,2); //where $datarows is the number of records obtained from the query $data_array[$i][2]=$Area;//Error message: Cannot use a scalar value as an array
The specific cycle is as follows
The code is as follows Copy code
$i=0; while($result=$db->fetch_array($query)) { $Area=$result["Area"]; $data_array[$i][2]=$Area; //Error! $i=$i+1;  } http://www.bkjia.com/PHPjc/628683.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628683.htmlTechArticleArray assignment in php is very simple. If it is a one-dimensional array assignment, it is simpler than a two-dimensional array or a multi-dimensional array. Now let me introduce to you various examples of assigning values ​​to arrays. If necessary...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!