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 回答