php - Replacing values in the array nvp -
i have been trying replace values in array i'll name array $currencies when print looks like.
array ( [0] => array ( [currencylabel] => usa, dollars [currencycode] => usd [currencysymbol] => $ [curid] => 1 [curname] => curname1 [check_value] => [curvalue] => 0 [conversionrate] => 1 [is_basecurrency] => 1 ) [1] => array ( [currencylabel] => india, rupees [currencycode] => inr [currencysymbol] => ₨ [curid] => 2 [curname] => curname2 [check_value] => [curvalue] => 0 [conversionrate] => 50 [is_basecurrency] => ) [2] => array ( [currencylabel] => zimbabwe dollars [currencycode] => zwd [currencysymbol] => z$ [curid] => 3 [curname] => curname3 [check_value] => [curvalue] => 0 [conversionrate] => 22 [is_basecurrency] => )
)
here having $conversionrate need divide values present in array $currencies [0] -> array -> [conversionrate] , replace in same place in array. , same operation [1] -> array -> [conversionrate] , on.. current approach follows
$conversionrate = 50; foreach ($currencies $key => $val) { $key['conversionrate'] = $key['conversionrate'] / $conversionrate; if($key['conversionrate'] == 1) { $key['is_basecurrency'] = 1; } else { $key['is_basecurrency'] = ''; } } print_r($key); die;
currently not working kindly help
your loop wrong, there no $key['conversionrate'], it's $val['conversionrate']. in fact there doesn't seems reason $key variable, can loop through array with
foreach ($currencies &$val)
also, want print_r($currencies), not $key
Comments
Post a Comment