I have an Array that contains some entries. Some are string other are int. and those are defined in MySQL with type (int, varchar). The array i create looks like this: (minified the array because too long)
[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
)
As you can see some of "month_spend" and/or "month_adops" is empty, the problem is that in PHP the value is converted to "NULL" when the field is Integer in database, so result gives me:
Incorrect integer value: '' for column 'month_spend' at row 2"
So i tried to change this inside an foreach loop like this:
$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;
}
}
but looks like the foreach loop does not edit the data?
&in$key => &$result. This will change the original array rather then having to create a replacement array.0coming from the database toNULL? Never seen that before. Additionally, please edit your question to add more details, do not use the comment section for thatIFNULL(month_budget, 0)