我有一个$_POST
数组,如下所示
Array
(
[questionTitle1] => question one
[questionNote1] => note one
[oprtionValue11] => green 1
[oprtionValue21] => blue 1
[oprtionValue31] => orange 1
[questionTitle2] => question two
[questionNote2] => note two
[oprtionValue5] => green 2
[oprtionValue6] => blue 2
[oprtionValue7] => orange 2
[oprtionValue8] => red 2
)
这里我想把数组分成单独的数组,比如当出现像questionTitle%这样的$ key时。
答案 0 :(得分:3)
试试这个
$filteredArray = array();
$indexPattern = '/questionTitle(.*)/';
foreach($_POST as $key => $value) {
if(preg_match($indexPattern, $key)) {
$filteredArray[$key] = $value;
}
}