Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP坚持循环练习_Php - Fatal编程技术网

PHP坚持循环练习

PHP坚持循环练习,php,Php,我被这个php循环卡住了。然后n=3,k=5,s=21。 有人能帮我吗 Rows 3. In the first row 5 chairs: 1 row: ⑁⑁⑁⑁⑁ (5 chairs) 2 row: ⑁⑁⑁⑁⑁⑁⑁ (7 chairs) 3 row: ⑁⑁⑁⑁⑁⑁⑁⑁⑁ (9 chairs) Chairs in total: 21 <?php for ($i=0; $i<=6; $i++) { for ($j=0; $j<$i; $j++) {

我被这个php循环卡住了。然后n=3,k=5,s=21。 有人能帮我吗

Rows 3. In the first row 5 chairs:
1 row: ⑁⑁⑁⑁⑁ (5 chairs)
2 row: ⑁⑁⑁⑁⑁⑁⑁ (7 chairs)
3 row: ⑁⑁⑁⑁⑁⑁⑁⑁⑁ (9 chairs)
Chairs in total: 21

<?php
 for ($i=0; $i<=6; $i++) {
      for ($j=0; $j<$i; $j++) {
         if($i == 1) {
             echo ''; 
         }else{
               echo '&#9281'; 
             } 
        } echo ' '; 
      }
 ?> 
第3行。第一排5把椅子:
第1行:⑁⑁⑁⑁⑁ (5张椅子)
第2行:⑁⑁⑁⑁⑁⑁⑁ (7张椅子)
第3行:⑁⑁⑁⑁⑁⑁⑁⑁⑁ (9席)
主席总数:21

我想您应该使用“if”语法。是这样吗? 如果不正确,你应该更详细地描述你的工作

<?php
// ...

for($i = 0; $i< sizeof($rows); $i++ ){
  if ($i % 2 == 0) {
    print "It's even";
  }
}

// ... If a row is an Array, use this one.

for($i = 0; $i< sizeof($rows); $i++ ){
  for($j = 0; $j< sizeof($rows[$i]); $j++ ){
    if ($j % 2 == 0) {
      print "It's even index of a row";
      //do Something.
    }
  }
}
?>

示例:当n=3和k=8时,必须获得s=30张椅子的顺序

创建一个PHP解决方案,指定变量中的N行队列,K-第一行应该有多少张椅子

例如:N=3;K=5

加载页面后(使用可用变量执行程序操作后),应显示以下内容:

第3排。第一排5把椅子: 队列1:⑁⑁⑁⑁⑁ (5张椅子) 队列2:⑁⑁⑁⑁⑁⑁⑁ (7张椅子) 队列3:⑁⑁⑁⑁⑁⑁⑁⑁⑁ (9席)
所需椅子总数:21张如果我正确理解您的要求, $n是您需要的行数, $k第1排的椅子数量

每排椅子加两张

<?php
$n = 3;
$k = 5;
for($i = 0; $i < $n; $i++) {
    if($i >= 1) {
        echo PHP_EOL;
    }
    echo str_repeat('-', $k + ($i * 2));
}

到目前为止您尝试了什么?显示一些代码我已经尝试过了,但我不明白为什么椅子在同一排我需要每隔一排加上两张椅子在一个循环中。我不明白“每隔一排”。这是双数吗?非常感谢。这正是我想要的