1 Oleh: Ahmad Ramadhani, S.KomPHP Array & Form Oleh: Ahmad Ramadhani, S.Kom
2 Array An array is a special variable, which can hold more than one value at a time. Contoh : $cars1="Volvo"; $cars2="BMW"; $cars3="Toyota"; Bisa diganti dengan : $cars=array("Volvo","BMW","Toyota");
3 Tipe Array In PHP, there are three types of arrays:Indexed arrays - Arrays with numeric index Associative arrays - Arrays with named keys Multidimensional arrays - Arrays containing one or more arrays
4 PHP Indexed Arrays The index can be assigned automatically (index always starts at 0): $cars=array("Volvo","BMW","Toyota"); or the index can be assigned manually: $cars[0]="Volvo"; $cars[1]="BMW"; $cars[2]="Toyota";
5 Cara memanggil isi array: <Cara memanggil isi array: Cara menghitung isi array :
6 "; } ?>
7 PHP Associative ArraysAssociative arrays are arrays that use named keys that you assign to them. There are two ways to create an associative array: $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); or: $age['Peter']="35"; $age['Ben']="37"; $age['Joe']="43";
8 Cara memanggil : "35","Ben"=>"37","Joe"=>"43"); echo "Peter is " . $age['Peter'] . " years old."; ?> Cara loop : "35","Ben"=>"37","Joe"=>"43"); foreach($age as $x=>$x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "
"; } ?>
9 Form Cara mengirim : Cara memanggil: Welcome
Your address is:
10 Form Cara mengirim : Cara memanggil: Welcome
Your address is: