Why use $$ to define an array, error cannot using string offset as an

Source: Internet
Author: User
Array $tongji1, $tongji 2, $tongji 3, $tongji 4, $tongji 5, $tongji 6, $tongji 7, $tongji 8, respectively
Structure similar to
$tongji 1=array
(
[KC1] = = Array
(
[Zong] =>2
[RS] =>3
)
[Kc2] = = Array
(
[Zong] =>4
[RS] =>5
)
)
$tongji 2=array
(
[KC1] = = Array
(
[Zong] =>4
[RS] =>5
)
[KC3] = = Array
(
[Zong] =>1
[RS] =>2
)
)
......
The simplicity contained in the array now wants to combine several arrays with the same kc*, using the following code
$tongjiz = $tongji 1;
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];
}
}
}

Now to $tongjiz[$k][zong]= $tongjiz [$k][zong]+$ $z [$k][zong];
Found to be because $ $z [$k][zong] This problem is not an array
But I can output the array when I Print_r ($ $z) alone
Start with Print_r ($ $z [$k])

Excuse me, this is why ah, thank you.


Reply to discussion (solution)

$ $z [$k] [' Zong ']
To write
${$z}[$k] [' Zong ']

$ $z [$k] [' Zong ']
To write
${$z}[$k] [' Zong ']



That's it, thank you so much.
has been resolved
  • Related Article

    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.