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...
|
|
|