PHP-从以特定字符串开头的数组中获取所有键
我有一个看起来像这样的数组:
array( 'abc' => 0,
'foo-bcd' => 1,
'foo-def' => 1,
'foo-xyz' => 0,
// ...
)
我如何仅获取以其开头的元素foo-
?
回答:
$arr_main_array = array('foo-test' => 123, 'other-test' => 456, 'foo-result' => 789);foreach($arr_main_array as $key => $value){
$exp_key = explode('-', $key);
if($exp_key[0] == 'foo'){
$arr_result[] = $value;
}
}
if(isset($arr_result)){
print_r($arr_result);
}
以上是 PHP-从以特定字符串开头的数组中获取所有键 的全部内容, 来源链接: utcz.com/qa/401556.html