Array 1:
$Arr1 = array( 'name/?' => 'apple', 'weight' => '30kg', );
Now we need to check whether isset( $Arr1['name/fruits'] ) exists in array 1. Key points: How to let PHP put it? Ignore fruits and return true
function my_isset($array, $key){ foreach($array as $k => $v) { if (strpos($k, '?') == -1) { if ($k == $key) { return true; } } else { $pattern = str_replace('?', '.+', $k); $pattern = str_replace('/', '\/', $pattern); if (preg_match('/'. $pattern . '/', $key)) { return true; } } } return false; } $a = [ 'aa' => 'dddd', 'xx/?' => 'dd', ]; var_dump(my_isset($a, 'aa'), my_isset($a, 'xx/dddd'), my_isset($a, 'xxx'));
According to your business logic, you only need to determine whether key is in name, that is, whether name/ can be found in name/fruits: strpos($name , substr($ key , 0 , -1))
key
name
name/
name/fruits
strpos($name , substr($ key , 0 , -1))
According to your business logic, you only need to determine whether
key
is inname
, that is, whethername/
can be found inname/fruits
:strpos($name , substr($ key , 0 , -1))