3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $ar = array('mopo_1' => 'honta', 'hinta' => 200, 'mopo_2' => 'jamaha', 'hinta' => 320, 'mopo_3' => 'susuki', 'hinta' => 310); function array_key_exists_wildcard ( $array, $search, $return = '' ) { $search = str_replace( '\*', '.*?', preg_quote( $search, '/' ) ); $result = preg_grep( '/^' . $search . '$/i', array_keys( $array ) ); if ( $return == 'key-value' ) return array_intersect_key( $array, array_flip( $result ) ); return $result; } $search = 'mopo*'; print_r( array_key_exists_wildcard( $ar, $search ) ); print_r( array_key_exists_wildcard( $ar, $search, 'key-value' ) );
based on vEccv
Output for 5.3.19 - 7.2.0
Array ( [0] => mopo_1 [2] => mopo_2 [3] => mopo_3 ) Array ( [mopo_1] => honta [mopo_2] => jamaha [mopo_3] => susuki )