PHP Assigning values to arrays (two-dimensional array assignment) _php tutorial

Source: Internet
Author: User
In the PHP array assignment is very simple, if it is a one-dimensional array assignment than a two-dimensional array or multidimensional array is simpler, below I will give you to the array assignment of various examples introduced, there is a need to understand the friend can refer to.

What about the PHP array assignment? As follows:

Example 1, one-dimensional array assignment

The code is as follows Copy Code

$My _array=array ();
$My _array[]= "www"
$My _array[]= "helpphp";
$My _array[]= "cn";


Destroying an 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);//The number of records $datarows for the query
$data _array[$i][2]= $Area;//Hint error: 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.html www.bkjia.com true http://www.bkjia.com/PHPjc/628683.html techarticle in PHP array assignment is very simple, if it is a one-dimensional array assignment than a two-dimensional array or multidimensional array is more simple, let me give you students to the array assignment of various examples introduced, there is a need ...

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