1

我有一个$_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
) 

在这里,我想在 $key like questionTitle% 出现时将数组分解为单独的数组。

4

1 回答 1

3

尝试这个

$filteredArray = array();
$indexPattern = '/questionTitle(.*)/';
foreach($_POST as $key => $value) {
    if(preg_match($indexPattern, $key)) {
        $filteredArray[$key] = $value;
    }
}
于 2012-06-13T11:32:39.677 回答