Why does Cannotusestringoffsetasanarray error occur after $ is defined as an array?

Source: Internet
Author: User
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

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.