gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
I have a php array like this: $a[0]['catid'] = 'a'; $a[1]['catid'] = 'b'; $a[2]['catid']…
- User
I have a php array like this: a[1]['catid'] = 'b'; $a[2]['catid'] = 'c';
- Assistant
You can loop through the array and check if the 'catid' value is equal to 'b':
$found = false; foreach ($a as $item) { if ($item['catid'] == 'b') { $found = true; break; } } if ($found) { echo "'b' exists in array \$a"; } else { echo "'b' does not exist in array \$a"; }Another way is to use the
array_columnfunction and check if the value 'b' exists in the 'catid' column:if (in_array('b', array_column($a, 'catid'))) { echo "'b' exists in array \$a"; } else { echo "'b' does not exist in array \$a"; }