我有这段代码:
$str='ياسمين';
$a=utf8Split(trim($str));
for($i=0;$i<=strlen($a);$i++)
{
$sql_char=("SELECT num FROM alphabet where letters = '$a[$i]'");
$result = mysql_query ($sql_char,$dbConn);
while($row = mysql_fetch_array($result))
echo $row['num'].'<br>';
}
答案 0 :(得分:0)
只需将$row['num']
添加到新的variable
$sum=0;
while($row = mysql_fetch_array($result)){
echo $row['num'].'<br>';
$sum=$sum+$row['num'];
}
echo $sum; //171
修改强>
function mb_str_split( $string ) {
# Split at all position not after the start: ^
# and not before the end: $
return preg_split('/(?<!^)(?!$)/u', $string );
}
$str = 'ياسمين';
$charlist = mb_str_split( $str );
print_r( $charlist );