0

私の質問は、この配列をどのように取得するかです:

Array (
    [0] => stdClass Object (
        [item] => 0
        [size] => 2657017
        [group] => MAXAT
        [description] => 265/70R17 MAXTRAC A/T 115T 00K
        [sort4] => 115
        [sort5] => T
        [sort6] =>
        [price] => 118.91
    )
    [1] => stdClass Object (
        [item] => 8127
        [size] => 2657017
        [group] => FZSUV
        [description] => 265/70R17 FUZION SUV OWL 115T 50K
        [sort4] => 115
        [sort5] => T
        [sort6] =>
        [price] => 137.81
    )
    [2] => stdClass Object (
        [item] => 0
        [size] => 2657017
        [group] => MAXAT
        [description] => LT265/70R17 MAXTRAC A/T 118S E 00K
        [sort4] => 118
        [sort5] => S
        [sort6] => E
        [price] => 153.79
    )
    [3] => stdClass Object (
        [item] => 1237
        [size] => 2657017
        [group] => ATS
        [description] => 265/70R17 GEO AT-S OWL 113S 50K
        [sort4] => 113
        [sort5] => S
        [sort6] =>
        [price] => 167.15
    )
)

それをこの配列に変換します(別のクエリを実行せずに):

Array (
    [0] => stdClass Object (
        [group] => MAXAT
        [price] => 118.91
    )
    [1] => stdClass Object (
        [group] => FZSUV
        [price] => 137.81
    )
    [2] => stdClass Object (
        [group] => MAXAT
        [price] => 153.79
    )
    [3] => stdClass Object (
        [group] => ATS
        [price] => 167.15
    )
)

私が達成しようとしているのは、グループと価格を最初の配列から新しい配列にプルすることだけです。

4

2 に答える 2

0

foreach を使用して配列をループし、値を新しい配列に挿入できますか?!

$new_array = array();
$i = 0;
foreach($array as $k => $v){
    $new_array[$i]['group'] = $v['group'];
    $new_array[$i]['price'] = $v['price'];
    $i++;
}
于 2013-10-09T20:35:52.283 に答える