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 のような 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 に答える