$ firstbloodkill array:
Array ( [0] => [1] => [2] => [3] => [4] => [5] => 1 [6] => [7] => [8] => [9] => )
我试图将空值设置为0。
我想做什么:
Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 1 [6] => 0 [7] => 0 [8] => 0 [9] => 0 )
我的代码:
foreach ($firstbloodkill as $key => $element)
{
if($element == "")
{
$firstbloodkill[$key] = 0;
}
}
它不起作用。我做错了什么?
编辑:我发现我做错了什么。数组名称是' firstBloodKill'。我将firstbloodkill更改为firstBloodKill并开始工作。对不起,我很蠢。
答案 0 :(得分:1)
var d = new Dictionary<string, string>
{
{"code", ItemCode},
{"descr", ItemDescription}
};
var b = new MvxBundle(d);
var r = new MvxViewModelRequest<SecondViewModel>(b, null, null);
var m = Mvx.Resolve<IMvxViewModelLoader>().LoadViewModel(r, null);
答案 1 :(得分:1)
您可以像{/ p>一样使用empty
功能
foreach($arr as &$v){
if(empty($v)){
$v = 0;
}
}
答案 2 :(得分:1)
您好您也可以使用array_map
进行此
<?php
function change($value){
if(empty($value))return 0;
else return $value;
}
$firstbloodkill = array(0 =>'',1 =>'' ,2 =>1,3 =>'' ,4 =>'' ,5 =>1 ,6 =>'' ,7 =>'' ,8 =>'' ,9=>'' );
$new = array_map('change',$firstbloodkill);
echo "<pre>";print_r($new);