LoginSignup
0
0

More than 5 years have passed since last update.

[1day1lang AdventCalender] day3 PHP

Posted at

環境設定

phpインストール

$ sudo apt-get install php
$ php -v
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )

Hello World!

$ php -r "echo 'Hello World!'.PHP_EOL;"
Hello World!

Apacheインストール

今回は必要ないが、Apatche2 もインストール

$ sudo apt-get install apache2

Apache が動いていることを確認

$ curl http://localhost

ツリー描画プログラム

tree.php
<?php

define("ASTER", "* ");
define("SPACE", " ");
define("EVE", 24);

$sumAster = 0;
$step = 0;

while($sumAster <= EVE) {
    $step ++;
    $sumAster += $step;
}
$trnk = EVE - ($sumAster - $step);

for ($i = 1; $i <= $step; $i++){
    if ($i < $step) {
        for ($j = $step; $j > $i; $j--) echo SPACE;
        for ($j = 1; $j <= $i; $j++)    echo ASTER;
    } else {
        for ($j = $i - $trnk; $j >= 1; $j--) echo SPACE;
        for ($j = 1; $j <= $trnk; $j++)      echo ASTER;
    }
    echo PHP_EOL;
}

実行

$ php tree.php 
      * 
     * * 
    * * * 
   * * * * 
  * * * * * 
 * * * * * * 
    * * * 

おわり

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0