Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Assignment one
- //problem no one
- // variable means container puts data temporay wise it's will be constant also when changed !
- $fname = "Sujon";
- $lname ="Shekh";
- echo "My name first name is {$fname} and my last name is {$lname}\n";
- printf ("My name first name is %s and my last name is %s\n",strtoupper($fname),strtoupper($lname));
- printf ('My name first name is %2$s and my last name is %1$s',$fname,$lname); //$fname is Arguments!!
- // printf can changed variable value and it's user friendly;
- echo "\n";
- //problem no two
- $birthYears = 1993;
- $recentYears = 2020;
- $birthYears2 = $recentYears - $birthYears; // this operation called operand;
- //number += 1 (+=Assingment operator); means number = number + 1 ;
- echo "My Age is {$birthYears2} years old";
- echo "\n";
- //Problem no three
- $d = 51;
- $o =051;
- $h = 0X5D;
- printf ("Various Number System is %d and %d also %d\n",$d,$o,$h);
- printf ("The Binary equivalent is %d to %b\n",$d,51);
- printf ('The Binary equivalent is %1$d to %1$b',51); //place holder!
- echo "\n";
- //Problem no four
- $product = 123.500;
- $product2 = 63.213;
- printf("Price is %07.2f,\n",$product);
- printf("Price is %07.2f,\n",$product2);
- //Problem no five
- $food = "apple";
- if ("Tuna" == $food || "salmon fish" == $food ||"shark" == $food ){ // "Tuna" == $food is scalar value;
- echo "{$food} is Vitamine 'D'";
- }elseif("apple"== $food || "mango"== $food || "pineaple"==$food){
- echo "{$food} is Fruit";
- }else{
- echo "its not avaiable in our store Sorry !!!!!!!";
- }
- echo "\n";
- //problem no six
- $year = 1900;
- if ($year % 4 ==0 &&($year % 100 !=0 || $year % 400 ==0))//it's called Nested ! //if (true && true) can print if any where false it's turn over false;
- //if (false || true) can print if any where false it's turn over true;
- {
- echo "$year Leap Year";
- }else{
- echo "$year not Leap Year";
- }
- echo "\n";
- // problem no seven
- $condition1 = false;
- $condition2 = true;
- $condition3 = false;
- if ($condition1 && $condition2 && $condition3){
- echo "Hello Sujon Shekh";
- }elseif ($condition1 && $condition2){
- echo "no 1";
- }elseif ($condition1){
- echo "no 2";
- }else {
- echo "no 3";
- }
- echo "\n";
- // problem number Eight
- $numb = 10 ;
- $numberCheck = (12 == $numb) ? "Twelve" : ((10 == $numb) ? "Ten" : "A Number"); //Ternary Operator can handle many nested wise!
- $numberCheck2 = ($numb %2 == 0) ? "Even Number " : "Odd Number";
- echo $numberCheck;
- echo "\n";
- echo $numberCheck2;
- echo PHP_EOL;
- // Problem number nine
- for ($i = 1; $i<=10; $i++){
- echo PHP_EOL;
- for( $j= 10-$i; $j >=1 ; $j--){
- echo " ";
- }
- for ($j = 1; $j<= $i ; $j++ ){
- echo " * ";
- }
- }
- echo PHP_EOL;
- //problem number ten
- $n = 10;
- for ($i = $n, $factorial = 1 ; $i > 1 ; $i--) {
- $factorial *= $i;
- }
- printf ("The factorial number of %d is %d",$n,$factorial);
- //Problem number eleven
- echo PHP_EOL;
- echo "Fibonacchi series : ";
- $very_old = 0;
- $old = 1;
- $new = 1;
- for ($i=0; $i<10; $i++){
- echo $very_old. " ";
- $old = $new;
- $new = $very_old + $old;
- $very_old = $old;
- }
- // Problem number tweleve !!
- echo PHP_EOL;
- $x = 51;
- $y = 51;
- $sujon = $x <=> $y; // Spacesheep operator
- if ($sujon == 1){
- echo "{$x} is greater than {$y}";
- }elseif ($sujon ==0){
- echo "{$x} is equales to {$y}";
- }elseif($sujon ==-1){
- echo "{$x} is smallar than {$y}";
- }
- //problem number thirteen
- echo "\n";
- $default_lat = 51.5;
- $default_lon = 29.5;
- $user_lat ;
- $lat = $user_lat ?? $default_lat; //null coales operator better than ternary operator
- echo $lat;
- if (isset($user_lat)){
- $lat = $user_lat;
- }else{
- $lat = $default_lat;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement