0

これは私が得たものです...

 $shop = array( array( first_name => "john", 
                      last_name => "doe"
                    ));         
 foreach($shop as $key => $value) {
    foreach($value as $key2 => $value2) {
            $shop[$key][$key2] = $shop[$key]['newname'];
            unset($shop[$key][$key2]);
        }}

print_r($shop);

どの出力

Array ( [0] => Array ( ) )
4

1 に答える 1

0

割り当て行(6行目)を変更してnewname動的にします。だから次のようなもの:

...foreach ($value as $key2 => $value2) {
    $newname = 'new_' . $key2;
    $shop[$key][$newname] = $shop[$key][$key2];
    unset($shop[$key][$key2]);
}...
于 2012-07-20T16:54:06.557 に答える