php - How to replace value inside an array? -
i have array shown below.
array (size=2) '1s1' => array (size=8) 'order_id' => int 0 'item_id' => int 1 'special_desc' => string 'special xxx' (length=11) 'qty' => int 2 'price' => int 50 'amount' => int 0 'created_at' => int 1376580193 'updated_at' => int 1376580193 '1s2' => array (size=8) 'order_id' => int 0 'item_id' => int 2 'special_desc' => string 'special yyy' (length=11) 'qty' => int 3 'price' => int 150 'amount' => int 0 'created_at' => int 1376580193 'updated_at' => int 1376580193
if wanted replace "order_id" of both elements of array new value before saving database, array function or technique can use?
thanks.
take @ array_walk
:
$array = array_walk( $array, function( $subarray ) { $subarray[ 'order_id' ] = 'somenewvalue'; } );
a simple foreach
work too.
// noting '&' reference call foreach( $array &$subarray ) { $subarray[ 'order_id' ] = 'somenewvalue'; } // or foreach( $array $key => $value ) { $array[ $key ][ 'order_id' ] = 'somenewvalue'; }
Comments
Post a Comment