array_splice 与多维数组?
好的,我对 PHP 还很陌生,目前正在尝试数组。举个例子,假设这是我的数组:
$t1 = array (
"basicInfo" => array (
"The Sineps",
"December 25, 2010",
"lemonpole_1g"
),
"overallRecord" => array (
"23",
"12",
"19",
""
)
);
根据我收集到的信息,我发现函数 array_splice 允许我指向数组中的特定索引并添加/删除数据。从我见过的使用此函数的所有示例中......仅使用了数字数组。现在我的问题是如何指向 ["overallRecord"][3](为空),并更新该字段?
为了进一步理解空字段代表“总分”:
$wins = $t1["overallRecord"][0] * 3;
$loss = $t1["overallRecord"][1];
$draw = $t1["overallRecord"][2];
$total = $wins + $draw;
所以总而言之,我想将变量 $total 添加到 ["overallRecord"][3]< /强>。它不一定必须使用array_splice,但是,如果您想出一种不同的方法来实现此尝试并保持简单或添加注释,请:)
提前致谢!
Okay so I'm fairly new to PHP and I am currently experimenting with arrays. As an example, lets assume this is my array:
$t1 = array (
"basicInfo" => array (
"The Sineps",
"December 25, 2010",
"lemonpole_1g"
),
"overallRecord" => array (
"23",
"12",
"19",
""
)
);
From what I could gather, I found out that the function array_splice allows me to point to a specific index in the array and add/remove data. From all of the examples that I've seen using this function...only numeric arrays were used. Now my question is how would I point to ["overallRecord"][3](which is empty) for example, and update that field?
For further understanding that empty field is for "total points":
$wins = $t1["overallRecord"][0] * 3;
$loss = $t1["overallRecord"][1];
$draw = $t1["overallRecord"][2];
$total = $wins + $draw;
So to sum it all up, I'd like to add the variable $total to ["overallRecord"][3]. It doesn't necessarily have to be with array_splice, however, if you come up with a different method to achieve this try and keep it simple or add comments please :)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解正确的话,只需做
If I understand correctly, simply do