Question about word group

Source: Internet
Author: User
May I ask questions about word group?


$ Test = array ();
Function abc ($ port, $ index = 0 ){
If (! Isset ($ GLOBALS ['test'] [$ index])
$ GLOBALS ['test'] [$ index] = array ();
$ GLOBALS ['test'] [$ index] [] = $ port;
}

?>

In the above code, test is defined as a one-dimensional array outside the function,
However, $ GLOBALS ['test'] [$ index] [] = $ port; in this way, test becomes a two-dimensional array.
Can it be understood that the number of data records in a row of this array is determined by $ port, that is, if $ port is 3, this
One row of the array contains three data records. Is that true? Thank you for your help.


Reply to discussion (solution)

Php arrays are not arrays in the traditional sense.
The concept of row and column can be attached only when it is a two-dimensional array.

Php arrays are not arrays in the traditional sense.
The concept of row and column can be attached only when it is a two-dimensional array.



Thank you for your reply.

How can I understand $ GLOBALS ['test'] [$ index] [] = $ port?

$ GLOBALS ['test'] [$ index] [] = $ port;
Equal
Array_push ($ GLOBALS ['test'] [$ index], $ port );

$ GLOBALS ['test'] [$ index] [] = $ port;
Equal
Array_push ($ GLOBALS ['test'] [$ index], $ port );



Thank you for your reply.

But I still don't know much about it.

For example, $ port = 1;
When $ GLOBALS ['test'] [$ index] [] = $ port; is run
$ GLOBALS ['test'] [$ index] [0] is 1. is that true ?. That is to say, it is a two-dimensional array. Or can it be understood that 2 is an array.


$ GLOBALS ['test'] [$ index] [] = $ port;
Equal
Array_push ($ GLOBALS ['test'] [$ index], $ port );



Thank you for your reply.

But I still don't know much about it.

For example, $ port = 1;
When $ GLOBALS ['test'] [$ index] [] = $ port; is run
$ GLOBALS ['test'] [$ index] [0] is 1. is that true ?. That is to say, it is a two-dimensional array. Or can it be understood that 2 is an array.



Yes, you can print it out and check it out.
$ GLOBALS ['test'] [$ index] [0] is actually a multi-dimensional full-size group.

I really have the skills to make simple things complicated.

$ Test = array ();
$ Port = 1;

$ GLOBALS ['test'] [$ index] [] = $ port;
Append $ port to array $ GLOBALS ['test'] [$ index]
Append $ port to the array $ test [$ index ].
After completion
$ GLOBALS ['test'] is a three-dimensional array.
$ Test is a two-dimensional array.

The reason is that the php array is not an array of the traditional meaning, because the array is homogeneous, that is, the number of columns in each row is the same
The array in php does not have this constraint. array (1, 2, 3), array (4 ))
In addition, the value marked as a continuous number at the position of the array element does not have this constraint on array (3 => array (1, 2, 3), 8 => array (4) in php ))
You can also mark array ('C' => array (, 3), array (4) with names (associated keys ))

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.