Make PHP ignore strings
扔个三星炸死你
扔个三星炸死你 2017-06-07 09:22:55
0
2
585

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

扔个三星炸死你
扔个三星炸死你

reply all(2)
漂亮男人
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'));
过去多啦不再A梦

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))

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template