Php array addition, I cannot understand. could you give me some good examples?

Source: Internet
Author: User
Php array addition, I cannot understand. could you give me some good examples?
$a ="a";$b ="b";$ay[$a][$b][]= 3;print_r($ay);

Output, Array ([a] => Array ([B] => Array ([0] => 3), indicates whether Array B exists in Array, an array exists in array B. The value of the array index 0 is 3.

//////////////////////////////////////
$ Me [$ a] [$ B] + = $ Me [$ k] [$ c]; // What is the value on the left after this addition ??
$ Me [$ z] [$ m] = $ Me [$ sy] [$ my]; // what will happen after this assignment ??

I have a big head for these two sentences. please help me. it is best to write an example to show them to me. my mind is really not very easy ..

I only know the following ..
$ A [] = 1;
$ B [] = 2;
Echo $ a [0] + B [0]; the result is 3.
Also understand
$ A [] = 1;
$ B [] = 2;
Echo $ a [0] = B [0]; result a [0] is 2;


Reply to discussion (solution)

$ Me [$ a] [$ B] + = $ Me [$ k] [$ c]; // What is the value on the left after this addition ??
$ Me [$ z] [$ m] = $ Me [$ sy] [$ my]; // what will happen after this assignment ??


This is a two-dimensional array representation that represents the value of an element. you can use it as a variable:
$ A + = 1;
$ A = 3;
So you can understand it.

$ Me [$ a] [$ B] + = $ Me [$ k] [$ c]; // What is the value on the left after this addition ??
This is short for, equivalent
$ Me [$ a] [$ B] = $ Me [$ a] [$ B] + $ Me [$ k] [$ c];
Equivalent
$ A = $ a + $ B;

$ Me [$ z] [$ m] = $ Me [$ sy] [$ my]; // what will happen after this assignment ??
$ Me [$ z] [$ m] and $ Me [$ sy] [$ my] both store a value.
Assume that $ Me [$ z] [$ m] stores 1 and $ Me [$ sy] [$ my] stores 2 values.
Then echo $ Me [$ z] [$ m] = $ Me [$ sy] [$ my];
The result is that $ Me [$ z] [$ m] is 2.

Php array () is a multi-dimensional array,
The value of one dimension is: array []
The two-dimensional value is: array [] []
And so on.
Returns the dimension of the array.

/*** Return the array dimension * @ param [type] $ arr [description] * @ return [type] [description] */function arrayLevel ($ arr) {$ al = array (0); function aL ($ arr, & $ al, $ level = 0) {if (is_array ($ arr) {$ level ++; $ al [] = $ level; foreach ($ arr as $ v) {aL ($ v, $ al, $ level) ;}} aL ($ arr, $ al); return max ($ al) ;}$ arr = array ('0' => '0',); echo arrayLevel ($ arr );

It is recommended to use the function array_merge () http://www.w3school.com.cn/php/func_array_merge.asp of php array to merge arrays

More hands-on, less eye-catching, remember to give your mind some oil

$Me = array(  array(1, 2, 3, 4),  array(4, 6, 7, 8),  array(9, 10, 11, 12),  array(13, 14, 15, 16),);$a = 0;$b = 1;$k = 2;$c = 3;$z = 3;$m = 3;$sy = 1;$my = 2;$Me[$a][$b] += $Me[$k][$c];$Me[$z][$m] = $Me[$sy][$my];print_r($Me);

Thank you!

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.