echo jquery in PHP 语法错误 - 找不到我的错误

echo jquery in PHP syntax error - can't find my mistake

我尝试在 PHP 中回显 jQuery 但无论我做什么,它都会给我以下错误:

Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ',' or ';' in /var/www/html/login/application/controllers/sellercentral.php on line 309

代码:

echo '<script>
    $( document ).ready(function() {
         $("#Drafts > tbody:last").append('foreach($this->central as      $key2 => $value2) {
            '<tr> 
            <td><a href='. $value2->Token .'>Edit</a></td>
            <td class=T id='. $value2-    >Token.'>'.htmlentities($value2->Title).'</td>
            </tr>
        '.}.' );

                         });

            </script>';

不能在 echo 语句中使用 foreach!像这样分解它们:

echo '<script>
      $( document ).ready(function() {
      $("#Drafts > tbody:last").append(';

foreach($this->central as $key2 => $value2) {
    echo '<tr> 
            <td><a href='. $value2->Token .'>Edit</a></td>
            <td class=T id='. $value2-    >Token.'>'.htmlentities($value2->Title).'</td>
          </tr>';
}

echo  ');});</script>';

我认为您应该在 foreach 循环中使用 echo。类似的东西 :

echo '<script>
    $( document ).ready(function() {
    $("#Drafts > tbody:last").append(';

foreach($this->central as      $key2 => $value2) {
    echo '<tr> 
        <td><a href='. $value2->Token .'>Edit</a></td>
        <td class=T id='. $value2-    >Token.'>'.htmlentities($value2->Title).'</td>
        </tr>'; 
}
echo ' );
    });
</script>';