nmohamm Posted May 18, 2010 Share Posted May 18, 2010 Can anyone help me with the following $var question thanks?: Extract and add together the numeric values from the string $var $var = '{"val_a":7,"val_b":5,"val_c":4,"val_d":6,"val_e":5}'; Answer: Link to comment https://forums.phpfreaks.com/topic/202207-var-extract-question-help/ Share on other sites More sharing options...
teamatomic Posted May 18, 2010 Share Posted May 18, 2010 something like: $array=explode(',',$var); foreach($array as $value) { list($junk,$number)=explode(':',$value); $count+=$number; } HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/202207-var-extract-question-help/#findComment-1060321 Share on other sites More sharing options...
kenrbnsn Posted May 19, 2010 Share Posted May 19, 2010 That string is JSON encoded string, so using the function json_decode and then use array_sum on the resultant array. Ken Link to comment https://forums.phpfreaks.com/topic/202207-var-extract-question-help/#findComment-1060340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.