<?php function familyName($fname) { echo "{$fname} Refsnes.<br>"; } familyName("Jani"); familyName("Hege"); familyName("Stale"); familyName("Kai Jim"); familyName("Borge");
<?php function familyName($fname, $year) { echo "{$fname} Refsnes. Born in {$year} <br>"; } familyName("Hege", "1975"); familyName("Stale", "1978"); familyName("Kai Jim", "1983");
//outputs !dlrow olleH echo strpos("Hello world!", "world") . "<br>"; //outputs 6 echo str_replace("World", "Dolly", "Hello World!") . "<br>"; //outputs hello dollyy! function writeMsg() { echo "Hello World!" . "<br>"; } writeMsg(); //call the function function familyName($fname, $year) { echo "{$fname} Ftik.Born in {$year} .<br>"; } familyName("Ulvie Ameilia", "1996"); function setHeight($minheight = 50) { echo "The height is : {$minheight} <br>"; } setHeight(350); setHeight(); //will use the default value of 50 setHeight(135); setHeight(80); function sum($x, $y) { $z = $x + $y; return $z; } echo "5+10= " . sum(5, 10) . "<br>";
* 知识点1:用户定义函数 */ function writeMsg() { echo "Hello world!<br>"; } writeMsg(); /** * 知识点2:PHP 函数参数 */ function familyName($fname) { echo "{$fname} Zhang.<br>"; } familyName("Jgirl"); familyName("Hong"); //function familyName($fname, $year){ // echo "$fname Zhang. Born in $year <br>"; //} //familyName("Li","1975"); /** * 知识点3:PHP 默认参数值 */ function setHeight($minheight = 50) { echo "The height is : {$minheight}<br>"; } setHeight(350); setHeight(); /** * 知识点4:返回值
<?php function familyName($fname, $year) { echo "{$fname} Refsnes. Born in {$year} <br>"; } familyName("hege", "1775"); familyName("Stale", "1978"); familyName("kai jim", "1783");
$color = "blue"; $txt = "w3school.com"; $x = 50; $y = 2; echo " I love " . $color . "<br>"; echo " My favorite color is " . $color . "<br>"; echo " Water is " . $color . "<br>"; echo " Sky is " . $color . "<br>" . "<br>"; function familyName($fname, $year) { echo "{$fname} Refsnes. Born in {$year} <br>"; } familyName("Pratama", "2001"); familyName("Geraldy", "2002"); familyName("Aditya", "2003"); familyName("Hutagalung", "2004") . "<br>" . "<br>" . "<br>"; echo "I love {$txt}!" . "<br>"; echo "I love " . $txt . "!" . "<br>" . "<br>"; echo $x / $y . "<br>"; echo strlen("BELAJAR") . "<br>"; echo str_word_count("BELAJAR PEMPROGRAMAN WEB") . "<br>"; echo strrev("TUGAS PRAKTIKUM") . "<br>"; echo strpos("GOOD MORNING", "MORNING") . "<br>" . "<br>"; echo str_replace("RANGKUM", "TUGAS", "WEB RANGKUM!") . "<br>"; function setHeight($minheight = 10) { echo "The height is :{$minheight} <br>"; } setHeight(5); setHeight(); setHeight(15);
echo "I Love" . $txt . "!" . "<br>" . "<br>"; echo $x / $y . "<br>"; echo strlen("HELLO TUGASSSSS") . "<br>"; //panjang string = 15 echo str_word_count("HELLO TUGASSSSS") . "<br>"; // jumlah kalimat = 2 echo strrev("INI APA AJA ISI NYA WKWKW OKE") . "<br>"; //membalikkan string echo strpos("HELLO TUGASSSSS", "TUGASSSSS") . "<br>" . "<br>"; //posisi string yang dicari berada pada kalimat ke 2 echo str_replace("Saputri", "Anggre", "Aditya Saputri") . "<br>" . "<br>"; familyName("Aditya"); familyName("Ashley"); familyName("Alice"); familyName("Sasha"); familyName("Fifty Shades of"); echo "<br>"; echo "<br>"; setHeight(350); setHeight(); // use the default value of 50 setHeight(135); setHeight(80); echo "<br>"; echo "5 + 10 = " . sum(5, 10) . "<br>"; echo "7 + 13 = " . sum(7, 13) . "<br>"; echo "2 + 4 = " . sum(2, 4) . "<br>"; echo "<br>"; writeMsg(); //call the function ?>
$color = "red"; $txt = "campus.com"; $x = 60; $y = 2; echo " I love " . $color . "<br>"; echo " My favorite color is " . $color . "<br>"; echo " Water is " . $color . "<br>"; echo " Sky is " . $color . "<br>" . "<br>"; function familyName($fname, $year) { echo "{$fname} Refsnes. Born in {$year} <br>"; } familyName("Aco", "2001"); familyName("Baco", "2002"); familyName("Bece", "2003"); familyName("Banggulu", "2004") . "<br>" . "<br>" . "<br>"; echo "<br>"; echo "I love {$txt}!" . "<br>"; echo "I love " . $txt . "!" . "<br>" . "<br>"; echo $x / $y . "<br>"; echo "<br>"; echo strlen("PRAKTIKUM") . "<br>"; //panjang string = 7 echo str_word_count("PEMPROGRAMAN WEB") . "<br>"; //jumlah kalimat = 3 echo strrev("TUGAS PRAKTIKUM") . "<br>"; //membalikkan string echo strpos("GOOD DAY", "DAY") . "<br>" . "<br>"; //posisi string yang dicari berada kalimat ke 2 echo str_replace("RANGKUM", "TUGAS", "WEB RANGKUM!") . "<br>"; function setHeight($minheight = 10)
function writeMsg() { echo "Hello world!"; } writeMsg(); // 调用函数 // 带参函数 function familyName($fname) { echo "{$fname} Zhang.<br>"; } familyName("Li"); familyName("Hong"); familyName("Tao"); familyName("Xiao Mei"); familyName("Jian"); //默认参数 function setHeight($minheight = 50) { echo "The height is : {$minheight} <br>"; } setHeight(350); setHeight(); // 将使用默认值 50 setHeight(135); setHeight(80); //返回值 function sum($x, $y) { $z = $x + $y; return $z;
?> <br><br> <?php echo str_replace("world", "PHP", "Hello world!"); ?> <br><br> <?php function familyName($fname, $tempat) { echo "Hello World! {$fname} is learning PHP at {$tempat} <br>"; } familyName("Hanif", "Lab"); familyName("Suges", "Home"); familyName("Ayu", "Puskom"); familyName("Ulvie", "405"); familyName("Wong", "411A"); ?> <br><br> <?php function setWeight($minweight = 50) { echo "The weight is : {$minweight} <br>"; } setWeight(65); setWeight(); setWeight(73); setWeight(80); ?> <br><br> <?php function sum($x, $y)
} namaKeluarga("Mei"); namaKeluarga("Sin"); namaKeluarga("Kei"); namaKeluarga("Yo"); namaKeluarga("Rin"); echo "</fieldset>"; echo "<fieldset>"; echo "<legend>12.Fungsi Dengan lebih dari satu Argumen </legend>"; function familyName($fname, $year) { echo "{$fname} Refsnes. Born in {$year} <br>"; } familyName("Hage", "1975"); familyName("Steal", "1978"); familyName("Kai", "1983"); echo "</fieldset>"; echo "<fieldset>"; echo "<legend>13.Fungsi dengan nilai default pada argumen</legend>"; function aturTinggi($min = 50) { echo "Tinggi = {$min} <br>"; } aturTinggi(356); aturTinggi(); //tetatur default dengan diatas aturTinggi(101); aturTinggi(80); echo "</fieldset>"; echo "<fieldset>"; echo "<legend>14.Fungsi yang mengembalikan nilai</legend>";
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP 两个函数参数</title> </head> <body> <?php function familyName($fname, $year) { echo "{$fname} Zhang. Born in {$year} <br>"; } familyName("Li", "1975"); familyName("Hong", "1978"); familyName("tao", "1983"); ?> </body> </html>
code to be executed; } */ function writeMsg() { echo 'Hello world!' . '<br>'; } writeMsg(); //PHP Function Arguments function familyName($fname) { echo "{$fname} Mugwagwa.<br>"; } familyName('Absolom'); familyName('Makabongwe'); familyName('Alison'); //The following example has a function with two arguments ($fname and $year): function familyNameYear($fname, $year) { echo "{$fname} Mugwagwa. Born in {$year}<br> "; } familyNameYear('Absolom', '1985'); familyNameYear('Makabongwe', '1984'); familyNameYear('Alison', '2015'); //PHP Default Argument Value //The following example shows how to use a default parameter. If we call the function setHeight() without arguments it takes the default value as argument: function setHeight($minHeight = 50) { echo "The height is : {$minHeight} <br>"; } setHeight(350);