CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2513|Reply: 0

cara lain buat looping dalam PHP

[Copy link]
Post time 31-12-2008 12:32 AM | Show all posts |Read mode
biasanya kalau kita loop dalam PHP sure guna brackets, tapi kali ini saya tunjukkan cara lain

// foreach
$aweks = ['maznah','siti','zubaidah'];
Foreach( $aweks as $awek ): // mulakan loop

  echo $awek;

endForeach;

//while
$awek = true;
While( $awek == true ):

  echo "Hello, saya awek cun";
  sleep(5);

endWhile;

// if else
if( !isset($awek) ):

  echo "saya tiada awek";

else:

  echo "saya dah ada awek";

endIf;

// switch
switch($awek):
  case 'maznah':
    echo "nama saya maznah";
  break;
  
  case 'siti':
    echo 'nama saya siti';
  break;
endSwitch;

// for
for($n = 1; $n < 10; $n++ ):

  echo "Saya mempunyai $n aweks";

endFor;



Enjoy

Rate

1

View Rating Log

Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

9-1-2025 08:22 PM GMT+8 , Processed in 0.090238 second(s), 18 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list