Advertisement
cska1312

stringsPHP

Jan 11th, 2023
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="utf-8" />
  5.     <title>{ Project Name }</title>
  6. </head>
  7.  
  8.  
  9.  
  10. <body>
  11.     <?php
  12.         $text = "Banana Apple Orange Apple Grape Banana Grape Grape Grape Banana Apple Orange Apple Grape Banana Grape Grape Grape";
  13.         $text = explode(" ", $text);
  14.         print_r($text);
  15.         echo "<hr>";
  16.  
  17.         $strUnique = [];
  18.         $wordUnique = "";
  19.         $flag = 0;
  20.         for($i = 0; $i < count($text); $i++)
  21.         {    
  22.             $flag = 0;
  23.             $wordUnique = $text[$i];
  24.             for($j = 0; $j < $i; $j++)
  25.             {
  26.                 if($wordUnique == $text[$j])
  27.                 {
  28.                     $flag = 1;
  29.                 }
  30.             }
  31.             if($flag == 0)
  32.             {
  33.                 array_push($strUnique, $text[$i]);
  34.             }
  35.         }
  36.         print_r($strUnique);
  37.         echo "<hr>";
  38.  
  39.         $strUniqueCount = [];
  40.         $broqch = 0;
  41.         for($j = 0; $j < count($strUnique); $j++){
  42.             $b = 0;
  43.             $wordUnique = $strUnique[$j];
  44.             for($i = 0; $i < count($text); $i++){
  45.                 if($wordUnique==$text[$i]){
  46.                     $broqch++;
  47.                 }
  48.             }
  49.             $strUniqueCount[$wordUnique] = $broqch;
  50.         }
  51.  
  52.         print_r($strUniqueCount);
  53.         echo "<hr>";
  54.  
  55.  
  56.     ?>
  57. </body>
  58. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement