###### tags: `self-study` `work`
Data: 2022/7/23 Name: 侯智晟
## Goals: Discrete math, PHP
## Work contents:
### Unisersal/Existential quantifier

### Chapter 5
#### 5-2-5 (condiction)? True : false
```php=
<?php require "../head.php";
date_default_timezone_set('Asia/Taipei');
$hour = date('H');
$string ="Current time is ";
$strTime = ($hour < 12 ) ? "AM" : "PM";
$hour = ($hour < 12 ) ? "$hour":$hour-12;
print $string . $hour . $strTime;
require "../tail.php";?>
```
There I try use date() to the get current time instead with write directly.
Before we use date(), we have to set the time zone. otherwise, time will display another time zone.
Reflection: Oh ? : is cool!!! Awesome XD
#### 5-2-6 Match fomula
```php=
<?php require "../head.php";?>
<body>
<form action= "matchFormula.php" method="POST">
<select name ="facialAttractiveness">
<option value = "95">100~90</option>
<option value = "85">90~80</option>
<option value = "75">80~70</option>
<option value = "60">70 ~</option>
</select>
<input type="submit" value="send">
</form>
</body>
<?php
$facialAttractiveness = $_REQUEST["facialAttractiveness"];
$rank = "";
if($facialAttractiveness>90) $rank="A";
else if ($facialAttractiveness>80) $rank="B";
else if ($facialAttractiveness>70) $rank="C";
else $rand="D--";
$respond =match($rank){
"A" => "要來我家看貓嗎",
"B" =>"好熱 可以去妳家吹電風扇嗎",
"C" =>"OH 可以教我 要怎麼加別人ig嗎 順便加一下妳的",
default => "我要去洗澡了"
};
?>
<?require "../tail.php";?>
```
Reflection: Match() like diction mixed with switch statement.
#### 5 Lab6 do/while practice
Question: 計算 本金10000 利息2.5%(year) 持續五年複利
```php=
<?php require "../head.php";
$captital = 10000;
$interestRate=1.025;
$years = 0;
do{
$captital= $captital * $interestRate;
$years+=1;
}while($years<5);
print $captital;
require "../tail.php";?>
```
Slove tought: Math (captital) * (1+Rate) = interest + captital.
Result:

### Chapter 6
#### 6-2-3 call by value or call by address XD
```php=
<?php require "../head.php";
function callByValue($value){
$value+=10;
echo $value;
};
function callByAddress(&$value){
$value+=10;
echo $value;
};
$num1 = 5;
$num2 = 10;
callByValue($num1);
callByAddress($num2);
print "</br>";
echo $num1;
echo $num2;
require "../tail.php";?>
```
Reflection: if you have learned pointer, I though it was strightforward.

We could obviously know if we use pass by value, we couldn't change the variable's value, on the other hand, if we use pass by reference we could change the variable's value.
#### 6-2-5 Nullable parameters and return valus
```php=
<?php require "../head.php";
$string ="meowmeowmeow";
var_dump($string);
unset($string);
var_dump($string);
echo "</br>" ;
echo "<---------------------------------->";
echo "</br>";
$name = "meowhecker";
function nullableFunction(?string $parameter){
echo $parameter;
echo "1";
};
nullableFunction(null);
require "../tail.php";?>
```
```php=
var_dump($variable)
```
Dumps information about variable
```php=
unset($variable)
```
it will let variable transform Null data type.
---
#### Nullable function
if we want to not pass by anything, we could use the nullable function.
function nullableFunction(?"datatype" $variable)
Use ? we could use null to be a parameter.
#### Default null nullable function
Just like this
```php=
function defaultNullableFunction(?float $number = 20){
$middle = $number/2;
for($i=0;$i<$number;$i++){
if($i<=$middle){
//uper part
for($uperLeftSpace=$number/2;$uperLeftSpace>$i;$uperLeftSpace--){
echo " ";
};
for($uperLeftStar=0;$uperLeftStar<$i;$uperLeftStar++){
echo "*";
}
for($uperRightStar=1;$uperRightStar<$i;$uperRightStar++){
echo "*";
}
echo "</br>";
}
else{
for($lowerLeftspace=$number/2;$lowerLeftspace<$i;$lowerLeftspace++){
echo " ";
}
for($lowerLeftStar=$number;$lowerLeftStar>$i;$lowerLeftStar--){
echo "*";
}
for($lowerLeftStar=$number-1;$lowerLeftStar>$i;$lowerLeftStar--){
echo "*";
}
echo "</br>";
}
};
};
defaultNullableFunction();
```
Result
