The most viewed items
Normally There are three types of array: Indexed Array, Associative Array and Multi-Dimentional Array.
1. Indexed Array (Works with number)
<?php
$snack = array('Banana', 'Ice-cream', 'Coconet', 'Mango', 'Orange');
$snack[1]='Alcohol';
echo $snack[1];
//print_r($snack);
?>
2. Associative Array (Works with name)
<?php
$snack = array('Banana' => 100, 'Apple' => 200, 'Cake' => 300);
echo 'The cake is '.$snack['Cake']. ' Kyat.';
?>
3. Multi-Dimentional Array
<?php
$food = array('Healthy'=>array('Salad'=>200, 'Milk'=>100, 'Coconet'=>200),
'Unhealthy'=>array('Alcohol'=>200, 'Beer'=>300));
foreach($food as $element => $inner_array){
echo '<br /><strong>'.$element.'</strong><br />';
foreach($inner_array as $inner_element => $item){
echo $inner_element.' = '.$item.'<br />';
}
}
?>
<?php
$string = 'I am Thet Naing Win and who are you?';
$find = '/000/';
function Match($find, $string){
if(preg_match($find, $string)){
return true;
}else{
return false;
}
}
if(Match($find, $string)){
echo 'Match Found!';
}else{
echo 'Match Not Found!';
}
?>
<?php
$string = 'Hi How are you?. I am Thet Naing Win. Nice to meet you!';
$find = '/000/';
if (preg_match($find, $string)){
echo 'Match Found!';
}else{
echo 'Match Not Found!';
}
?>
<?php
if(isset($_POST['roll'])){
$rand = rand(000, 999);
echo 'You rolled a '.$rand.'.';
}
?>
<form action = "rand.php" method = "POST">
<input type = "submit" name = "roll" value = "Roll a Dice">
</form>
<?php
if(isset($_POST["username"]) && isset($_POST["password"])){
$username = $_POST["username"];
$password = $_POST["password"];
if(!empty($username) && !empty($password)){
echo 'Welcome to TNW, '.$username.'!';
}else{
echo 'Fill in all fields!';
}
}
?>
<form action = "test.php" method = "POST">
Username:<br />
<input type = "text" name = "username"><br /><br />
Password:<br />
<input type = "password" name = "password"><br /><br />
<input type = "submit" value = "Log In">
</form>
<?php
function Add($num1, $num2){
$result = $num1 + $num2;
return $result;
}
function Divide($num1, $num2){
$result = $num1/$num2;
return $result;
}
$info = Add(Add(5,5), Divide(4,2));
echo $info;
?>
<?php
function MyName(){
echo 'Thet Naing Win.';
}
echo 'My Name is ';
MyName();
?>
<?php
$count = 1;
$message = 'Hello!';
do {
echo $count.'. '.$message.'</br>';
$count ++;
}
while($count<=10)
?>
<?php
$text = 'I am Thet Naing Win.';
$count = 1;
while($count <= 10){
echo $count. ' '.$text.'!</br>';
$count ++;
}
?>
<?php
$text = 'I am Thet Naing Win.';
for($count = 1; $count <= 10; $count++){
echo $count. ' '.$text. '!</br>';
}
?>
<?php
$food = array('Healthy'=>array('Salad', 'Milk', 'Coconet', 'Ground_nut'),
'Unhealthy'=>array('Alcohol', 'Beer', 'Ice_cream'));
foreach($food as $element => $inner_element){
echo '</br><strong>'.$element.'</strong></br>';
foreach($inner_element as $item){
echo $item.'</br>';
}
}
?>
$date = 'Sunday';
switch($date){
case 'Saturday';
case 'Sunday';
echo 'It is weekend!';
break;
default;
echo 'It is not weekend day!';
break;
}
?>