php - Find array elements that have a certain key-name prefix -


i have associative array lots of elements , want list of elements have key name prefix.

example:

$arr = array(   'store:key' => 1,   'user' => 'demo',   'store:foo' => 'bar',   'login' => true, );  // need with: // function should return elements key starts "store:" $res = list_values_by_key( $arr, 'store:' );  // desired output: $res = array(   'store:key' => 1,   'store:foo' => 'bar', ); 

you :

$arr = array(   'store:key' => 1,   'user' => 'demo',   'store:foo' => 'bar',   'login' => true, );  $arr2 = array(); foreach ($arr $array => $value) {     if (strpos($array, 'store:') === 0) {         $arr2[$array] = $value;     } } var_dump($arr2); 

returns :

array (size=2) 'store:key' => int 1 'store:foo' => string 'bar' (length=3) 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -