Reputation:
this answer maybe on google but i couldnt find it because i dont know the exact keywords for this. The situation is as follows. I have an array called $value that contains 2 types of arrays:
[12] => Array (
[id] => phone
[class] => phone
[config] => Array (
[disabled] => 1
[value] => 1
)
)
[46] => Array (
[id] => email
[class] => email
[config] => Array (
[display_type] => disabled
[value] => 1
)
)
As you may see, they are almost the same except for the fact that one contains an array called "disabled" and the other "display_type". What im trying to do is to count how many of each type i have. I tried with this:
foreach ( $value as $col ) {
if ( $col->config == 'disabled' ) {
$total_default++;
} elseif ( $col->config == 'display_type' ) {
$total_custom++;
}
}
but didnt work. I know it must be very simple but i just cant figure it out.
Thank you.
Upvotes: 0
Views: 89
Reputation: 160833
$col
is an array, not object.
foreach ($value as $col) {
if (array_key_exists('disabled', $col['config'])) {
$total_default++;
} else if (array_key_exists('display_type', $col['config'])) {
$total_custom++;
}
}
Upvotes: 1