I have the following code:
$count_table = array();
foreach ($events_tab as $event) {
if(isset($event["nature"])){
$count_table[$event["nature"]]++;
}
}
The array events_tab is like this :
Array
(
[0] => Array
(
[nature] => 300
[id] => 100828698
)
[1] => Array
(
[nature] => 3001
[id] => 100828698
)
)
I get the error : Undefined offset: 300 in this line : $count_table[$event["nature"]]++;. Please help me!! Thx in advance!!
$count_table[300]isn't set, but you're trying to increment the value that it holds..... how can you increment a value that doesn't exist?$count_table[$event["nature"]]++;withisset($count_table[$event["nature"]]) ? $count_table[$event["nature"]]++ : $count_table[$event["nature"]] = 1;$count_table$count_table = array_count_values(array_column($events_tab, 'nature', 'nature'));should work with recent versions of PHP