0% found this document useful (0 votes)
171 views

$color Array ('White', 'Green', 'Red', 'Blue', 'Black')

The document contains 9 programming problems involving PHP arrays. The problems cover various array operations like displaying array elements, inserting/deleting elements, calculating averages/extremes, removing duplicates, nested for loops, and more. Sample outputs are provided for most problems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
171 views

$color Array ('White', 'Green', 'Red', 'Blue', 'Black')

The document contains 9 programming problems involving PHP arrays. The problems cover various array operations like displaying array elements, inserting/deleting elements, calculating averages/extremes, removing duplicates, nested for loops, and more. Sample outputs are provided for most problems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

 $color = array('white', 'green', 'red', 'blue', 'black');


Write a script which will display the following string - 
"The memory of that scene for me is like a frame of film forever frozen at that
moment: the red carpet, the green lawn, the white house, the leaden sky. The
new president and his first lady. - Richard M. Nixon"
and the words 'red', 'green' and 'white' will come from $color.

2. $color = array('white', 'green', 'red'') 


Write a PHP script which will display the colors in the following way :
Output :
white, green, red,

 green
 red
 white

3. $ceu = array( "Italy"=>"Rome", "Luxembourg"=>"Luxembourg", "Belgium"=>


"Brussels", "Denmark"=>"Copenhagen", "Finland"=>"Helsinki", "France" =>
"Paris", "Slovakia"=>"Bratislava", "Slovenia"=>"Ljubljana", "Germany" => "Berlin",
"Greece" => "Athens", "Ireland"=>"Dublin", "Netherlands"=>"Amsterdam",
"Portugal"=>"Lisbon", "Spain"=>"Madrid", "Sweden"=>"Stockholm", "United
Kingdom"=>"London", "Cyprus"=>"Nicosia", "Lithuania"=>"Vilnius", "Czech
Republic"=>"Prague", "Estonia"=>"Tallin", "Hungary"=>"Budapest",
"Latvia"=>"Riga", "Malta"=>"Valetta", "Austria" => "Vienna",
"Poland"=>"Warsaw") ;

Create a PHP script which displays the capital and country name from the above
array $ceu.

Sample Output :
The capital of Netherlands is Amsterdam 
The capital of Greece is Athens 
The capital of Germany is Berlin 
-------------------------
-------------------------
4. $x = array(1, 2, 3, 4, 5);
Delete an element from the above PHP array. After deleting the element, integer
keys must be normalized. 
Sample Output :
array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) } 
array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(5) }

5. $color = array(4 => 'white', 6 => 'green', 11=> 'red');


Write a PHP script to get the first element of the above array. 
Expected result : white

6. Write a PHP script that inserts a new item in an array in any position. 
Expected Output :
Original array : 
1 2 3 4 5 
After inserting '$' the array is :
123$45

7. Write a PHP script to calculate and display average temperature, five lowest
and highest temperatures. 
Recorded temperatures : 78, 60, 62, 68, 71, 68, 73, 85, 66, 64, 76, 63, 75, 76,
73, 68, 62, 73, 72, 65, 74, 62, 62, 65, 64, 68, 73, 75, 79, 73
Expected Output :
Average Temperature is : 70.6 
List of seven lowest temperatures : 60, 62, 63, 63, 64, 
List of seven highest temperatures : 76, 78, 79, 81, 85,

Write a PHP program to remove duplicate values from an array which contains
only strings or only integers

8. Create a script that displays 1-2-3-4-5-6-7-8-9-10 on one line. There will be no


hyphen(-) at starting and ending position.
9. Write a PHP script that creates the following table using for loops. Add
cellpadding="3px" and cellspacing="0px" to the table tag. 

1 * 1 = 11 * 2 = 2 1 * 3 = 3 1 * 4 = 4 1 * 5 = 5
2 * 1 = 22 * 2 = 4 2 * 3 = 6 2 * 4 = 8 2 * 5 = 10
3 * 1 = 33 * 2 = 6 3 * 3 = 9 3 * 4 = 123 * 5 = 15
4 * 1 = 44 * 2 = 8 4 * 3 = 124 * 4 = 164 * 5 = 20
5 * 1 = 55 * 2 = 105 * 3 = 155 * 4 = 205 * 5 = 25
6 * 1 = 66 * 2 = 126 * 3 = 186 * 4 = 246 * 5 = 30
10. Write a PHP script using nested
for loop that creates a chess board as shown below. 
Use table width="270px" and take 30px as cell height and width.

You might also like