I am getting an error on this array. Array is:
我在这个数组中得到一个错误。数组是:
$array = array(
['parkingMode'] => array(
[0] => 123
[1] => 124
[2] => 266
),
['owlMode'] => array(
[0] => 124
[1] => 129
[2] => 266
)
);
how could be this correct?
这怎么可能正确呢?
UPDATE:
更新:
Now I extend my question. Suppose I have an empty array like
现在我扩展我的问题。假设我有一个空数组
`$newArray = array("parkingMode"=>array(),
"owlMode"=>array()
);
And what I am doing is pushing elements inside a foreach loop like,
我所做的是在一个foreach循环中推动元素,
foreach($devices as $k => $v) {
$dev = $redis->hGetAll($v);
//print_r($dev);
if(array_key_exists('owlMode', $dev)){
if($dev['owlMode'] =='on'){
array_push($newArray["parkingMode"], $k);
}
}
if(array_key_exists('parkingMode', $dev)){
if($dev['parkingMode'] =='on'){
array_push($newArray["owlMode"], $k);
}
}
}
//print_r($newArray);
Then why this is giving me result like array in the format:
那么为什么这给我的结果是数组的格式:
$array = array(
['parkingMode'] => array(
[0] => 123
[1] => 124
[2] => 266
),
['owlMode'] => array(
[0] => 124
[1] => 129
[2] => 266
)
);
`
”
2 个解决方案
#1
4
Elements in array should be separated by comma,
. This is correct format:
数组中的元素应该用逗号分隔。这是正确的格式:
$array = array(
'parkingMode' => array(
0 => 123,
1 => 124,
2 => 266
),
'owlMode' => array(
0 => 124,
1 => 129,
2 => 266
)
);
#2
1
You should create associate array.In an associative array, the keys assigned to values can be arbitrary and user defined strings.
您应该创建关联数组。在关联数组中,分配给值的键可以是任意的和用户定义的字符串。
array(
"parkingMode" => array(
[0] => 123,
[1] => 124,
[2] => 266
), "owlMode" => array(
[0] => 124,
[1] => 129,
[2] => 266
));
#1
4
Elements in array should be separated by comma,
. This is correct format:
数组中的元素应该用逗号分隔。这是正确的格式:
$array = array(
'parkingMode' => array(
0 => 123,
1 => 124,
2 => 266
),
'owlMode' => array(
0 => 124,
1 => 129,
2 => 266
)
);
#2
1
You should create associate array.In an associative array, the keys assigned to values can be arbitrary and user defined strings.
您应该创建关联数组。在关联数组中,分配给值的键可以是任意的和用户定义的字符串。
array(
"parkingMode" => array(
[0] => 123,
[1] => 124,
[2] => 266
), "owlMode" => array(
[0] => 124,
[1] => 129,
[2] => 266
));