title: for loop not working correctly with json encode Php
body: <p>I am trying to fetch members ratings from the database using ajax. I passed a function to the JSON, even though it returned a value in the function but it doesn't execute the for loop condition.</p>
  
  <p>Here is my code, the loop failed to execute. What am I doing wrong?</p>
  
  <pre><code>    function mrate($irate) {
          $class = "fa-star star-filled";
          for ($i = 0; $i &lt; 5; $i++) {
              if ($irate &lt;= $i) {
                  $class = "fa-star-o empty";
              }
              return '&lt;i class="fa ' . $class . '"&gt;&lt;/i&gt;';
          }
      }
  
      $perPage = 2;
      if (isset($_GET["page"]) &amp;&amp; isset($_GET["page"])) {
          $page = $_GET["page"];
          $pid = $mysqli-&gt;real_string_escape($_GET["pid"]);
      } else {
          $page = 1;
          $pid = $mysqli-&gt;real_string_escape($_SESSION['pid']);
      };
  
      $startFrom = ($page - 1) * $perPage;
      $sqlQuery = "SELECT id, name,
          review, rating, added_date
          FROM review_rating
          where product_id = '$pid'
          ORDER BY id ASC LIMIT $startFrom, $perPage";
      $result = mysqli_query($mysqli, $sqlQuery);
      $paginationHtml = '';
      while ($row = mysqli_fetch_assoc($result)) {
  
          $img = '&lt;img class="rounded-circle" width="50" src="' . $set['installUrl'] . 'assets/img/login.png" alt="' . $row["name"] . '"/&gt;';
          $irate = $row['rating'];
  
          $paginationHtml .= '&lt;div  class="product-review pb-4 mb-4 border-bottom"&gt;';
          $paginationHtml .= '&lt;div class="d-flex mb-3"&gt;';
          $paginationHtml .= '&lt;div class="media media-ie-fix align-items-center mr-4 pr-2"&gt;' . $img;
          $paginationHtml .= '&lt;div class="media-body pl-3"&gt;&lt;h6 class="font-size-sm mb-0"&gt;' . $row["name"] . '&lt;/h6&gt;';
          $paginationHtml .= '&lt;span class="font-size-ms text-muted"&gt;' . $row['added_date'] . '&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;';
          $paginationHtml .= '&lt;div&gt;&lt;div class="star-rating"&gt;' . mrate($irate) . '&lt;/div&gt;&lt;/div&gt;';
          $paginationHtml .= '&lt;/div&gt;';
          $paginationHtml .= '&lt;p class="font-size-md mb-2"&gt;' . $row['review'] . '&lt;/p&gt;';
          $paginationHtml .= '&lt;/div&gt;';
      }
      $jsonData = array(
          "html" =&gt; $paginationHtml,
      );
      echo json_encode($jsonData);
  </code></pre>