---
# System prepended metadata

title: 3/31 學習護照

---

# 3/31 學習護照

## 
陳節軒
jerrychen.livego@gmail.com
## 基本功
[online editor](https://paiza.io/en/projects/new)
### PHP
- 打印文字
```php=
 echo "hello php is easy"; 
```
- 設定變數、文字與變數相加
```php=
$name = "jerry";
 echo "hello ".$name. ",php is easy"; 
 echo "hello $name ,php is easy"; 
```
- 數字邏輯印算
```php=
$firstNum = 100;
$secondNum = 200;
echo $firstNum+secondNum;
```
```php=
$firstNum = 100;
$secondNum = $firstNum * 2 + 10;
echo $firstNum+secondNum;
```
- 如果
```php=
if($weather == "rainning") {
  echo "bring an umbrella";
  echo "wear a raincoat";
  echo "wear rain boots";
}
```
```php=
if($weather == "rainning") {
  echo "bring an umbrella";
  echo "wear a raincoat";
  echo "wear rain boots";
}else{
  echo "yeah~~~~happy";
}

```
- for loop
```php=
for ( $i=0 ; $i<10 ; $i++ ) {
　echo $i. '-' ;
}
```
```php=
$nums = array(1,2,3,4,5,6,7,8,9);
foreach($nums as $num){
    echo $num;
}
```

## TO DO 1
![](https://i.imgur.com/0MxxyuW.png)

### Answer 印星星
```php=
<!-- for($i = 6; $i > 0 ; --$i){

    for($x =  $i ; $x >= 0 ; $x--){
        print('*');
    }
     print('<br>');
}
print('*') -->
```


## TO DO 2 九九乘法表
![](https://i.imgur.com/OwITkVJ.png)


```htmlmixed=
<table border="1px"> 
    <tr>
        <td></td>
    </tr>
</table>
```

```php=
<table border="1px"> 
<?php
  for($i=1;$i<=9;$i++) {  
    echo "<tr>";  
    for ($j=1;$j<=9;$j++)  {  
      echo "<td>$i * $j = ".$i*$j."</td>";  
    }  
      echo "</tr>";  
   }  
?>
</table>  
```
## TO DO 3  符合格式列印資料
![](https://i.imgur.com/CqrR0WH.png)

```php=
$count = 5;
for($i= 1;$i <= $count;$i++){
    echo "$i";
    for($x = 1; $x <= ($count-1); $x++){
        echo " ".$i+$count*$x; 
    }
    echo "<br />";
}    
```


## TO DO 4 西洋棋盤
![](https://i.imgur.com/Bhl4DJS.png)

### Answer 

```htmlmixed=
<table width="270px" cellspacing="0px" cellpadding="0px" border="1px"> 
<tr>
    <td height=30px width=30px bgcolor=#FFFFFF></td>
    <td height=30px width=30px bgcolor=#000000></td>
</tr>
</table> 
```


```php=
<table width="270px" cellspacing="0px" cellpadding="0px" border="1px"> 
<?php
  for($row=1;$row<=8;$row++)  {  
      echo "<tr>";  
      for($col=1;$col<=8;$col++)  {  
        $total= $row + $col;  
        if($total%2==0){  
            echo "<td height=30px width=30px bgcolor=#FFFFFF></td>";  
        }  
        else{  
            echo "<td height=30px width=30px bgcolor=#000000></td>";  
        }  
      }  
      echo "</tr>";  
    }  
?>
</table>  
``` 

## TO DO 5 發牌
```php=
/*撲克花色*/
$pokers = [
    'Spades',
    'Hearts',
    'Diamonds',
    'Clubs',
];
/*人頭牌*/
$cards = [
   '1',
   '2',
   '3',
   '4',
   '5',
   '6',
   '7',
   '8',
   '9',
   '10',
   'J',
   'Q',
   'K',
];
```
##### 亂數
```php=
rand(0,51)
```
##### array push
```php    
 array_push(urArry, $value);
```




```php=
$pokers = [
    'Spades',
    'Hearts',
    'Diamonds',
    'Clubs',
];
/*人頭牌*/
$cards = [
   '1',
   '2',
   '3',
   '4',
   '5',
   '6',
   '7',
   '8',
   '9',
   '10',
   'J',
   'Q',
   'K',
];

$allCards = [];

foreach ($cards as $card){
    foreach($pokers as $poker){
        array_push($allCards, $poker.$card);
        // print($poker.$card);
        // print("<br/>");
    }
}

for($i = 100 ; $i > 0 ; $i--){
    $shuf = rand(0,51);
    $shuf_2 =  rand(0,51);
    $tack = $allCards[$shuf];
    $allCards[$shuf] = $allCards[$shuf_2];
    $allCards[$shuf_2] = $tack ;
}

print_r($allCards);
```
