2016-10-10 7 views
1

各特定のカテゴリに含まれる単語の数をカウントする必要があります。たとえば、私の場合は、今、特定のリスティングにいくつの単語が含まれているかを数えます。グループワード数変換テーブルLaravel 5.3

@if (str_word_count($stats->description) < 250) 
    0 - 249 
@elseif(str_word_count($stats->description) >= 250 && str_word_count($stats->description) <= 500) 
    250 - 500 
@elseif(str_word_count($stats->description) >= 501 && str_word_count($stats->description) <= 750) 
    500 - 750 
@else 
    750+ 
@endif 

最後に、各カテゴリでカウントする必要があるテーブルがあります。このように:

<table class="table table-condensed table-responsive"> 
         <thead> 
          <tr> 
           <th class="text-center" colspan="6">Conversion Rate For Word Count</th> 
          </tr> 
          <tr> 
           <th>0 - 249 words</th> 
           <th>250 - 500 words</th> 
           <th>500 - 750 words</th> 
           <th>750 + words</th> 
          </tr> 
         </thead> 
         <tbody> 
          <tr> 
           <td></td> 
           <td></td> 
           <td></td> 
           <td></td> 
          </tr> 
         </tbody> 
        </table> 

0-249語などのすべてのリストはどのように数えますか?

答えて

1

あなたのために働くようなものはありますか?

PHP

$counts = ['0-249'=>0, '250-499'=>0, '500-749'=>0, '750+'=>0]; 
@if (str_word_count($stats->description) < 250) 
    $counts['0-249']++; 
@elseif(str_word_count($stats->description) >= 250 && str_word_count($stats->description) <= 500) 
    $counts['250-499']++; 
@elseif(str_word_count($stats->description) >= 501 && str_word_count($stats->description) <= 750) 
    $counts['500-749']++; 
@else 
    $counts['750+']++; 
@endif 

HTML

   <table class="table table-condensed table-responsive"> 
        <thead> 
         <tr> 
          <th class="text-center" colspan="6">Conversion Rate For Word Count</th> 
         </tr> 
         <tr> 
          <th>0 - 249 words</th> 
          <th>250 - 499 words</th> 
          <th>500 - 749 words</th> 
          <th>750 + words</th> 
         </tr> 
        </thead> 
        <tbody> 
         <tr> 
          <td><?php echo $counts['0-249']; ?></td> 
          <td><?php echo $counts['250-499']; ?></td> 
          <td><?php echo $counts['500-749']; ?></td> 
          <td><?php echo $counts['750+']; ?></td> 
         </tr> 
        </tbody> 
       </table> 
+0

はい、動作します – David