LoginSignup
0
0

More than 1 year has passed since last update.

Laravelのルーティングで1から10までを加算し、その結果を戻り値とする無名関数を作成

Last updated at Posted at 2021-06-04

ルーティングで利用されている無名関数の中ではPHPの任意の処理を書ける

<?php

Route::get('/sum', function () {
     $sum = 0;
    for ($i = 0; $i <= 10; $i++) {
     $sum = $sum + $i;
    }
    return '1から10までの合計は'.$sum;
});

image.png

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