我正在将这个javascript代码转换为PHP,但它似乎无法正常工作 [英] I am converting this javascript code into PHP, but it seems not working

查看:64
本文介绍了我正在将这个javascript代码转换为PHP,但它似乎无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是Javascript中的代码:



Below is the code in Javascript:

const printNumberStarMatrix = function (row, col) {

    for (let i = 1; i <= row; ++i) {
        let strToPrint = "";
        for (let j = col - i; j >= 1; --j) {
            strToPrint = j + strToPrint;
        }
        while (strToPrint.length < col) {
            strToPrint += "*";
        }
        console.log(strToPrint);
    }
}





我的尝试:



以下是我用php编写的代码:





What I have tried:

Below is the code I have written in php:

<?php
$printNumberStarMatrix = function ($row, $col) {
	for ($i = 1; $i <= $row; ++$i) {
		$strToPrint = "";
			for ($j = $col - $i; $j >= 1; --$j) {
				$strToPrint = $j + $strToPrint;
			}
	}
	while ($strToPrint < $col) {
		$strToPrint += "*";
		}
echo $strToPrint;
	};
$printNumberStarMatrix(5, 6);
?>

推荐答案

printNumberStarMatrix = function(
printNumberStarMatrix = function (


row,


col){
for(
col) { for (


这篇关于我正在将这个javascript代码转换为PHP,但它似乎无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆