slimboy007 Posted June 21, 2010 Share Posted June 21, 2010 how can i extract and add together the numeric values from the string $numbers $numbers = '{"val_a":7,"val_b":5,"val_c":4,"val_d":6,"val_e":5}'; Quote Link to comment https://forums.phpfreaks.com/topic/205393-how-can-i-extract-and-add-the-numbers-from-a-string/ Share on other sites More sharing options...
trq Posted June 21, 2010 Share Posted June 21, 2010 Considering that string is serialized data. <?php $numbers = '{"val_a":7,"val_b":5,"val_c":4,"val_d":6,"val_e":5}'; $array = unserialize($numbers); echo array_sum($array); ?> Quote Link to comment https://forums.phpfreaks.com/topic/205393-how-can-i-extract-and-add-the-numbers-from-a-string/#findComment-1074885 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.