Closed. This question needs to be more focused。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
                        
                        2年前关闭。
                                                                                            
                
        
$query33=mysql_query("SELECT * FROM order_payment_tb where order_status='Success'",$conn) or die (mysql_error());
while($row33=mysql_fetch_array($query33)) {
  $query3=mysql_query("SELECT * FROM user_order_tb where status='Pending' and order_id='".$row33['order_id']."'",$conn) or die (mysql_error());
  $count5=mysql_num_rows($query3);
  {
    echo $count5; ?>
  <?php
  }
}
?>


我从mysql获得的结果数据是0111,我想将数据显示为3,即(0 + 1 + 1 + 1 = 3)。
请帮忙

最佳答案

str_split将数字拆分为一个数组,并使用array_sum将数组中的每个数字求和

$data替换为结果数据

array_sum(str_split($data));

关于php - 如何在PHP中将0111计为0 + 1 + 1 + 1 = 3 ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42224337/

10-12 02:40