Why is an error reported when $ is defined as an array? the values have arrays $ tongji1, $ tongji2, $ tongji3, $ tongji4, $ tongji5, $ tongji6, $ tongji7, $ tongji8
The structure is similar
$ Tongji1 = Array
(
[Kc1] => Array
(
[Zong] => 2
[Rs] => 3
)
[Kc2] => Array
(
[Zong] => 4
[Rs] => 5
)
)
$ Tongji2 = Array
(
[Kc1] => Array
(
[Zong] => 4
[Rs] => 5
)
[Kc3] => Array
(
[Zong] => 1
[Rs] => 2
)
)
......
The conciseness contained in the array now we want to merge the several arrays with the same kc * and use the following code
$ Tongjiz = $ tongji1;
For ($ x = 2; $ x <9; $ x ++ ){
$ Z = "tongji". $ x;
Foreach ($ z as $ k =>$ v ){
If (array_key_exists ($ k, $ tongjiz )){
$ Tongjiz [$ k] [zong] = $ tongjiz [$ k] [zong] + $ z [$ k] [zong];
} Else {
$ Tongjiz [$ k] =$ $ z [$ k];
}
}
}
An error occurs when $ tongjiz [$ k] [zong] = $ tongjiz [$ k] [zong] + $ z [$ k] [zong ];
It is found that because $ z [$ k] [zong] is not an array.
But I can output
Print_r ($ z [$ k]) will not work.
Excuse me, why? what should I do? thank you.
Reply to discussion (solution)
$ Z [$ k] ['zong ']
To write
$ {$ Z} [$ k] ['zong ']
$ Z [$ k] ['zong ']
To write
$ {$ Z} [$ k] ['zong ']
This is the case. thank you very much.
Resolved