<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Simple function with argument - no return value</title> </head> <body> <?php function sayHi($name) { echo "Hi, {$name}!"; } $visitor = 5; sayHi($visitor); ?> </body> </html>
<?php namespace btvphp\stuff; function sayHi() { return 'Hi'; } echo \btvphp\stuff\sayHi(); // Hi echo sayHi(); // Hi
// "taguchi" => 200, // "fkoji" => 800, // "dotinstall" => 600, // ]; // // var_dump($sales["fkoji"]); //800 // $sales["fkoji"] = 900; // var_dump($sales["fkoji"]); //900 //foreach ($sales as $key => $value){ // echo "($key) $value "; //} // $colors = ["red","blue","pink"]; // var_dump($colors[1]); //blue // foreach ($colors as $value){ // echo "$value "; //} // foreach if while for コロン構文 // foreach ($colors as $value): // echo "$value "; // endforeach; // 関数 function sayHi($name = "taguchi") { //echo "hi!".$name; return "hi! " . $name; } //sayHi("Tom"); //sayHi("Bob"); //sayHi(); $s = sayHi(); var_dump($s);
/* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ use App\Events\LoanWasCreated; use App\Events\UserWasCreated; use App\Loan; use Carbon\Carbon; Route::get('/', function () { return sayHi(); /* $record = Loan::create([ 'applicant_id' => 4, 'farmer_id' => 12, 'app_date' => Carbon::now(), 'default_due_date' => Carbon::createFromFormat('Y-m-d','2015-12-15'), 'due_date' => Carbon::createFromFormat('Y-m-d','2015-12-15'), 'loan_type_id' => 2, 'status_id' => 1, 'crop_year' => '2015', 'season' => 'S', 'loc_id' => 5, 'region_id' => 3, 'user_id' => 3 ]); event(new LoanWasCreated($record));*/
?> </p> <br> <h2>Make your own functions</h2> <br> <?php function sayHi ($person){//you can give more than one attributes like age, race etc echo "Hello, $person! How are you?<br>"; } sayHi("Matt"); sayHi("Simon"); sayHi("JK"); sayHi("John"); sayHi("Sarah"); ?> <br> <?php //return function sayBye ($person){ return "Bye, $person! <br>"; } sayBye("1"); // doesn't show it online because it just used "return" echo sayBye ("2"); ?>
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Simple function with no arguments</title> </head> <body> <?php function sayHi() { echo 'Hi!'; } sayHi(); ?> </body> </html>