空数组 php,空到0-php数组

我有一个包含一些项的数组。有些是字符串,另一些是int,这些是在mysql中用类型(int,varchar)定义的。我创建的数组如下:

(由于太长而缩小了数组)

[3] => Array

(

[account_id] => *******

[month_id] => 201903

[month_comment] => 4,5% spend flat

[month_spend] => 23000

[month_budget] => 0

[month_adops] => 1035

[month_adops_forecast] => 1035

)

[4] => Array

(

[account_id] => ******

[month_id] => 201905

[month_comment] =>

[month_spend] =>

[month_budget] => 0

[month_adops] =>

[month_adops_forecast] => 45

)

[5] => Array

(

[account_id] => *******

[month_id] => 201906

[month_comment] =>

[month_spend] =>

[month_budget] => 0

[month_adops] =>

[month_adops_forecast] => 92

)

就像你看到的

"month_spend"

和/或

"month_adops"

为空,问题是在PHP中,当数据库中的字段为整数时,值被转换为“空”,因此结果给出:

Incorrect integer value: '' for column 'month_spend' at row 2"

所以我试着在foreach循环中改变这个:

$result_replace = array();

foreach ($data_replace as $key => $result) {

$result['month_id'] = substr_replace($result['month_id'], '2019', 0, 4);

if(empty($result['month_budget'])) {

$result['month_budget'] = 0;

$result_replace[] = $result;

}

else if(empty($result['month_spend'])) {

$result['month_spend'] = 0;

$result_replace[] = $result;

}

}

但看起来foreach循环没有编辑数据?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值