我有一个数组:
<?php
$array = [
'fruits' => [
'apple' => 'value',
'orange' => 'value'
],
'vegetables' => [
'onion' => 'value',
'carrot' => 'value'
];
Run Code Online (Sandbox Code Playgroud)
我也有一个字符串:
$string = 'fruits[orange]';
Run Code Online (Sandbox Code Playgroud)
有没有办法检查字符串中指定的 - 数组键 - 是否存在于数组中?
例如:
<?php
if(array_key_exists($string, $array))
{
echo 'Orange exists';
}
Run Code Online (Sandbox Code Playgroud)