可能重复:
数组键上的模式匹配
我需要获取具有特定键模式的数组中的所有元素。例如在这个数组中:
$items = array(
"a" => "1",
"b" => "2",
"special_1" => "3",
"c" => "4",
"special_2" => "5",
"special_3" => "6",
"d" => "7"
);
我需要所有带有包含字符串的键的元素special_
。这些应该定义一个新数组:
$special_items = array(
"special_1" => "3",
"special_2" => "5",
"special_3" => "6",
);
while
除了循环,还有什么聪明的方法吗?