Вы находитесь на странице: 1из 5

PHP Basics Tutorial 01

(1) Write a PHP script to Iterate through following Array using for loop? $array_ex=array("Apple","Banana","Mango","Orange","Grapes")

(2) Write a PHP script to iterate through following array using while loop? $array_ex=array("Apple","Banana","Mango","Orange","Grapes")

(3) Execute following programs and explain outputs?


<?php $str = 'This is a test.'; $first = $str[0];

echo $first.'<br>';

$third = $str[2];

echo $third.'<br>';

$str = 'This is still a test.'; $last = $str[strlen($str)-1];

echo $last.'<br>';

$str = 'Look at the sea'; $str[strlen($str)-1] = 'e';

echo $str.'<br>';

$third = $str{2};

echo $third .'<br>'; ?>

<?php $foo = 1 + "10.5"; echo $foo.'<br>'; $foo = 1 + "-1.3e3"; echo $foo.'<br>'; $foo = 1 + "-1.3E-3"; echo $foo.'<br>'; $foo = 1 + "bob-1.3e3"; echo $foo.'<br>'; $foo = 1 + "bob3"; echo $foo.'<br>'; $foo = 1 + "10 Small Pigs"; echo $foo.'<br>'; $foo = 4 + "10.2 Little Piggies"; echo $foo.'<br>'; $foo = "10.0 pigs " + 1; echo $foo.'<br>'; $foo = "10.0 pigs " + 1.0; echo $foo.'<br>'; ?>

(4) * ** *** **** ***** ****** *******

******** ********* ********** Print above output using two nested for loops. (5) Write a program to get the absolute value of an integer number. Hint: Use Mathematical functions (6) Write a program to print Square Root of 1 to 100. Hint: Use Mathematical functions 1 =>1 2=> 1.4142135623731 . . 100=>10

(7) Write a program to find the maximum value of array using for loop. $no=array(34,54,56,78,21,23,45,67,65)

(8) Following is a multidimensional array $students =array( array( "name"=>"saman", "Subject1"=>45, "Subject2"=>35, "Subject3"=>56), array( "name"=>"Ravindra","Subject1"=>66, "Subject2"=>75, "Subject3"=>56), array( "name"=>"Bhagya", "Subject1"=>95, "Subject2"=>65, "Subject3"=>56), array( "name"=>"Nishanthi", "Subject1"=>87, "Subject2"=>66, "Subject3"=>56),

array( "name"=>"Thilini", "Subject1"=>77, "Subject2"=>97, "Subject3"=>56));

Above array contains student names and three subject marks. You need to calculate total and average for the each student and print in a following table.

Name

Subject1

Subject2

Subject3

Total

Average

(9) Write a program using wile loop to print the elements of the following array $presidents = array(1 => 'Washington',Name1=> 'Adams', 'Jefferson', Name2=> 'Adams, 'Madison'); Hint:Use array_keys() functions. (10) Write a program to merge following two arrays.

$array1 = array("color" => "red", 2, 4); $array2 = array("a", "b", "color" => "green", "shape" => "trapezo id", 4); Hint: Use array functions.

Вам также может понравиться