Getting an Undefined Offset error here -- apparently from the $newval array.
Note that the {exp} tag is not PHP, and is simply a sql query by my CMS system which creates the $bags array for me.
<?php
$bags = array();
$newval = array();
$pattern = "[^0-9]";
{exp:query sql="SELECT m_field_id_1 as bags FROM exp_member_data WHERE m_field_id_1 IS NOT NULL"}
$bags[] = "{bags}";
{/exp:query}
foreach ($bags as $key => $value) {
for ( $i = 0, $s = strlen($value); $i < $s; $i++) {
if ( is_numeric($value[$i]) ) {
$newval[$key] .= $value[$i];
}
}
}
$sum = array_sum($newval);
$format = number_format($sum);
echo $format;
?>