How To Supplant The Value Of Sure Enough Telephone Commutation Inwards Array Using Php?
Today I needed to supersede the value of for certain fundamental inwards array. I create non request to add together roughly other fundamental too value. Rather, supersede an existing key's value amongst roughly other value.
Since I am using an associative array too knew the key's advert equally well. I wrote the next code too it worked.
PHP
If you lot could desire to rebuild the array too perish along the element's order, you lot tin give the sack utilization next function.
Since I am using an associative array too knew the key's advert equally well. I wrote the next code too it worked.
PHP
$array = array('product' =>'iphone', 'price' =>'4500', 'model'=>'5G'); $array['price'] = '5700'; // country you lot wanted to alter the value of fundamental 'price' print_r($array); //outputs : array('product' =>'iphone', 'price' =>'5700', 'model'=>'5G');
If you lot could desire to rebuild the array too perish along the element's order, you lot tin give the sack utilization next function.
<?php business office replace_key($find, $replace, $array) { $arr = array(); foreach ($array equally $key => $value) { if ($key == $find) { $arr[$replace] = $value; } else { $arr[$key] = $value; } } furnish $arr; } //example $array = array('test' => 0, 'replace this' => 1, iii => 'hey'); echo '<pre>', print_r($array, true), '</pre>'; $array = replace_key('replace this', 'with this', $array); echo '<pre>', print_r($array, true), '</pre>'; ?>Sumber http://developer-paradize.blogspot.com
Comments
Post a Comment