php中的多维数组
有人知道我如何重新填充这种数组吗?我需要插入一些值,而不是0。 我做了两个循环,一个用于创建数组结构,另一个用于填充数组,但是当我想要归档时,我得到一个错误“偏移量0” 这些值是整数 我有一个php中的多维数组,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,有人知道我如何重新填充这种数组吗?我需要插入一些值,而不是0。 我做了两个循环,一个用于创建数组结构,另一个用于填充数组,但是当我想要归档时,我得到一个错误“偏移量0” 这些值是整数 我有一个for循环: $lista[$medio] = Array(); for ($count=1; $count<=53; $count++) { $lista[$medio][$count] = 0; } for ($j = 1; $j <= $counter ; $j++
for
循环:
$lista[$medio] = Array();
for ($count=1; $count<=53; $count++) {
$lista[$medio][$count] = 0;
}
for ($j = 1; $j <= $counter ; $j++) {
$f = $d[0]['f'];
$xn= $d[0]['d'];
$xww= explode("/",$xn);
$kw = $xww[0];
// Here I'm filling the list, I need the values from $f to be inserted instead of the 0 from the array. I think this is the correct way to do that:
$lista[$medio][intval($kw)]+= $f;
print_r($lista);
}
您可以使用PHP函数数组填充键 来自PHP的示例:
<?php
$keys = array('foo', 5, 10, 'bar');
$a = array_fill_keys($keys, 'Banane');
print_r($a);
?>
我希望对你有用 我们这里没有d美元和x美元。。它们看起来怎么样?我们也没有$medio。我们无法尝试您的代码,如果我理解正确,我认为错误发生在其他地方?“要归档吗”?对不起,伙计们,我刚刚编辑过$lista[$medio][intval($kw)]+=$f;这是$kw,这个变量有内部整数
<?php
$keys = array('foo', 5, 10, 'bar');
$a = array_fill_keys($keys, 'Banane');
print_r($a);
?>