Php multi-dimensional array acquisition problem, beginner

Source: Internet
Author: User
{Code...} I want to get array (1, 2, 3, 4, 5); how does the value in this one-dimensional array get it? I got it like this: $ array [0], but it doesn't work. It seems like java and c. Php is a beginner. He is currently trying to switch from the front-end to the backend;

$array = array(1,2,3,4,5); $array[0] = array(a,b,c,d,e,f,g); $array[1] = array(A,B,C,D,E,F,G);

I want to get array (, 5); how do I get the values in this one-dimensional array?

I got it like this: $ array [0], but it doesn't work. It seems like java and c.

Php is a beginner. He is currently trying to switch from the front-end to the backend;

Reply content:

$array = array(1,2,3,4,5); $array[0] = array(a,b,c,d,e,f,g); $array[1] = array(A,B,C,D,E,F,G);

I want to get array (, 5); how do I get the values in this one-dimensional array?

I got it like this: $ array [0], but it doesn't work. It seems like java and c.

Php is a beginner. He is currently trying to switch from the front-end to the backend;

var_dump($array);

Click it and you will understand it.

php$array = array(1,2,3,4,5);

When you assign values in this way, it is actually equivalent to array (0 => 1, 1 => 2, 3 => 4, 4 => 5 );
When the key (or subscript) is not specified, it is automatically started and incremented with 0.
Then you assign a value to $ array [0] And the array will become

phparray(0=>array(a,b,c,d,e,f,g), 1=>2, 3=>4, 4=>5);

That is to say, the original 1 has become an array, so the array (, 5) cannot be obtained, because the original value has been changed.
You can write the traversal as follows:

phpforeach($arr as $var) {    print_r($var);}

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.