I have an array $categories as follows;
Array
(
[0] => Array
(
[category_id] => 0
)
[1] => Array
(
[category_id] => 3
)
)
I want to apply some condition in foreach as follows;
Note: following condition is not working;
foreach ($categories as $key=> $category)
{
if($category['category_id']===0)
{
$categories[$key]['category_name'] = 'NA';
}
else
{
$categories[$key]['category_name'] = 'something';
}
}
so my expected result will become;
Array
(
[0] => Array
(
[category_id] => 0
[category_name] => NA
)
[1] => Array
(
[category_id] => 3
[category_id] => something
)
)
0is string you are checking with===operator which will match string with its datatype also. Check it please. And use'0'in current condition.'0'with condition or use==operator.