php - Split string into custom format -
how can split string custom format?
input string:
14157.72,39140.94,36383.66,38508.00,8424.00
expected output:
['14157.72'],['39140.94'],['36383.66'],['38508.00'],['8424.00']
current code:
foreach($amount[0] $aountlist){ //$aountlist.= "'".$aountlist->hpiamount.','; print_r($aountlist->hpiamount); $defineamount = [$aountlist->hpiamount]; }
how can change code expected output?
try -
$string = '14157.72,39140.94,36383.66,38508.00,8424.00'; $temp = array(); $str = explode(',', $string); foreach($str $val){ $temp[] = "[".$val."]"; } echo implode(',', $temp);
Comments
Post a Comment