PHP Multidimensional Array acquisition problem, beginner

Source: Internet
Author: User

$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 an array (1,2,3,4,5); How is the value of this one-dimensional array obtained?

I get it this way: $array [0] but no, the impression seems to be java,c.

PHP is a beginner, currently this cock is trying to turn from the front to the background;

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 an array (1,2,3,4,5); How is the value of this one-dimensional array obtained?

I get it this way: $array [0] but no, the impression seems to be java,c.

PHP is a beginner, currently this cock is trying to turn from the front to the background;

var_dump($array);

Just call it and see it.

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

When you assign a value like this, it's actually the equivalent of an array (0=>1, 1=>2, 3=>4, 4=>5);
When you do not specify a key (or subscript), it is automatically initialized and incremented by 0.
Then you give $array[0] an array of assignments that will become

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

That is to say that the original 1 has become an array, so you cannot get to array (1,2,3,4,5), because the original value has been changed by you.
You want to traverse can write like this:

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.