SHARE
TWEET

yofik

yofikur Nov 5th, 2018 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ----------------------------------------
  2. <?php  
  3. /*pengulangan
  4. //for
  5. //while
  6. //do .. while
  7. foreach : Khusus array*/
  8.  
  9. for( $i=0; $i < 5; $i++ ) {
  10.     echo "hello world<br>";
  11. }
  12. ?>
  13. ----------------------------------------
  14. //foreach
  15. <?php
  16. foreach (array(1, 2, 3, 4) as &$value) {
  17.     $value = $value * 2;
  18.     echo "$value <br> ";
  19. }
  20. ?>
  21. ----------------------------------------
  22. //kondisi else if
  23. <?php
  24. $x=80; //Nilai siswa yang diinputkan
  25. if($x >= 100){
  26. echo "A";
  27. }else if($x >=80){
  28.     echo "B";
  29. }else if($x >=60){
  30.     echo "C";
  31. }else if($x >=40){
  32.     echo "D";
  33. }else if($x >=20){
  34.     echo "E";
  35. }          
  36. ?>
  37. ----------------------------------------
  38. //kondisi IF
  39. <?php
  40. $x=10;
  41. if($x < 20){
  42.     echo"Benar";
  43. }   else if ($x ==20){
  44.     echo"Bingo!";
  45. }   else{
  46.     echo"salah";
  47. }
  48. ?>
  49. ----------------------------------------
  50. //perulangan didalam perulangan
  51. <!DOCTYPE html>
  52. <html>
  53. <head>
  54.     <title> Latihan Array</title>
  55. </head>
  56.     <title> Latihan Array</title>
  57.     <style>
  58.         .kotak {
  59.             width: 50px;
  60.             height: 50px;
  61.             background-color: red;
  62.             text-align: center;
  63.             line-height: 50px;
  64.             margin: 6px;
  65.             float: left;
  66.             transition: 0.5s;
  67.             }
  68.             .kotak:hover {
  69.                 transform: rotate(360deg);
  70.                 border-radius: 50%;
  71.             }  
  72.             .clear {
  73.                 clear: both;
  74.                
  75.             }
  76.     </style>       
  77. <body>
  78.  
  79. <?php
  80. $angka= [
  81.     [1,2,3,4],
  82.     [5,6,7,8],
  83.     [9,10,11,12],
  84.     ];
  85. ?>
  86. <?php foreach( $angka as $a ) : ?> 
  87. <?php foreach( $a as $b ) : ?>
  88.     <div class="kotak"><?= $b; ?> </div>
  89.     <?php endforeach; ?>
  90.     <div class="clear"></div>
  91. <?php endforeach; ?>   
  92. </body>
  93. </html>
  94. ----------------------------------------
  95. //function
  96. <?php
  97.     /* function
  98.        untuk menampilkan tanggal dengan format tertentu */
  99.     // echo date("l,d-M-Y");
  100.  
  101.      // time
  102.      // Unix Timestam / EPOCH time
  103.      // detik yang sudah berlalu sejak 1 januari 1970
  104.      // echo time();
  105.      // echo date("d M Y",time()-60*60*24*100);
  106.  
  107.      // mktime
  108.      // membuat sendiri detik
  109.      // mktimes(0,0,0,0,0,0)
  110.      // jam, menit, detik, bulan, tanggal, tahun
  111.      // echo date("l",mktime(0,0,0,8,29,1998));
  112.  
  113.      //strtotime
  114.      echo date("l",strtotime("29 aug 1998"));
  115. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top