如何以JSON格式显示值?

什鲁蒂

在那里我想以 JSON 格式显示数据

我想以 JSON 格式显示 if 和 else 语句数据

        foreach($share_amount as $value)
        {
         if($value<$total_avg){
          $a= $total_avg-$value; 
          $data2['pay_amount'] = $a;   
          $data2['member_id'] = $detail;
          $data2['contribution_response'] = "Need to pay"; 
         }
         else
         {
         $b= $total_avg-$value; /* the share amount stored and calculated*/
        ....
         $data2['contribution_response'] = "Need to take";
         }
         echo json_encode(array($data2));  
         /*storing in json but not getting displayed in the format*/   
什鲁蒂
This is how I got the answer
     foreach($share_amount as $value)
        {
             if($value<$total_avg){
                $a= $total_avg-$value;

        $data2['pay_amount'] = $a;   
        $data2['member_id'] = $detail;
        $data2['contribution_response'] = "Need to pay";
         }
         else
             {
        $b= $total_avg-$value;
        $edata['pay_amount'] = $b;   
        $edata['member_id'] = $detail;
        $edata['contribution_response'] = "Need to take";
         //echo json_encode($data2);

            }
            echo "\n";

        }
         echo json_encode(array($data2,$edata)); 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章