0% found this document useful (0 votes)
17 views3 pages

WebPro2023 Assignment1

This document outlines an assignment for a Web Programming course. It provides 4 problems to solve involving PHP arrays, strings, tables, and menus. For each problem, the instructor provides examples of the expected input, output, and formatting for solutions. Students are to write PHP code to demonstrate the given functions and save their work in specified files, including a utilities.php file for common functions. The assignment is due on March 3rd and must be submitted in a zipped folder with the student's full name.

Uploaded by

Blank User
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

WebPro2023 Assignment1

This document outlines an assignment for a Web Programming course. It provides 4 problems to solve involving PHP arrays, strings, tables, and menus. For each problem, the instructor provides examples of the expected input, output, and formatting for solutions. Students are to write PHP code to demonstrate the given functions and save their work in specified files, including a utilities.php file for common functions. The assignment is due on March 3rd and must be submitted in a zipped folder with the student's full name.

Uploaded by

Blank User
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Instructor: Imad Hadi Hasan Issued: 2023-02-22

Web Programming 2023


Assignment #1: Basics of PHP Language
Deadline: 2023-03-03

Problem 1: Give an appropriate example for each of the following array functions,
specify or print the input value(s) and print the outputs in a file called array.php:
1. is_array() 9. array_pop()
2. in_array() 10. array_values()
3. array_merge() 11. array_map()
4. array_keys() 12. array_slice()
5. array_key_exists() 13. array_diff()
6. array_shift() 14. array_search()
7. array_unshift() 15. array_reverse()
8. array_push() 16. implode()

Problem 2: Give an appropriate example for each of the following string functions, print
the input value(s) and print the outputs in a file called string.php:
1. strlen() 11. strtok() 21. addslashes()
2. substr() 12. trim() 22. strip_tags()
3. strpos() 13. ltrim() 23. stripcslashes()
4. chr() 14. rtrim() 24. htmlentities()
5. ord() 15. chop() 25. htmlspecialchars()
6. str_split() 16. number_format() 26. str_word_count()
7. str_replace() 17. strtoupper() 27. explode()
8. str_repeat() 18. strtolower() 28. md5()
9. strrev() 19. ucfirst() 29. sha1()
10. str_pad() 20. ucwords() 30. crypt()

Note:
1. the examples in above problmes should be in the following format:
Input: P1: "Hello World";
Function: strlen()
Output: 11
2. For printing arrays in readable layout, define a dump() function in a separate file called
utilities.php, then include the utilities in both array.php and string.php.

Page 1 of 3
Instructor: Imad Hadi Hasan Issued: 2023-02-22

Problem 3: Write a PHP function called render_table($array) in a utilties.php, that takes


a multi-dimension associative array as an argument, then, it renders the array as a dynamic
HTML table. Note that the number of columns is dynamic based on the associative keys in the
array rows, finally, test the following scenarios function in a separate file called table.php.

Example1:
Input: let input_array = [
["name": "Zara Azad", "age": 20, "email": "[email protected]"],
["name": "Ahmed Rafiq", "age": 25, "email": "[email protected]"],
["name": "Darbaz Ghafur", "age": 28, "email": "[email protected]"],
];

Output:
# Name Age Email
1 Zara Azad 20 [email protected]
2 Ahmed Rafiq 25 [email protected]
3 Darbaz Ghafur 28 [email protected]

Example2:

Input: let input_array = [


["name": "Zara Azad", "phone": "+964000110011"],
["name": "Ahmed Rafiq", "phone": "+964000223311"],
["name": "Darbaz Khudhr", "phone": "+964000440444"],
];

Output:
# Name Phone
1 Zara Azad +964000110011
2 Ahmed Rafiq +964000223311
3 Darbaz Khudhr +964000440444

Page 2 of 3
Instructor: Imad Hadi Hasan Issued: 2023-02-22

Problem 4: Write a PHP function called array_to_ul($menu) in utilities.php that


converts an associative array into a dynamic HTML list of links, use recursive function to iterate
any associative array in the following format as shown in Example 3. Then, test the following
scenario in a separate file called menu.php.

Example 3:
Input: $menu = [
"home" => ["title"=>"Home", "link"=>"home.php"],
"about" => ["title"=>"About", "link"=>"about.php"],
"departments"=> [
"title"=>"Departments",
"link"=>"#",
"children" => [
"software" => ["title"=>"Software Department" , "link"=>"software.php"],
"civil" => ["title"=>"Civil Department" , "link"=>"civil.php"],
"electrical"=> ["title"=>"Electrical Department", "link"=>"elect.php"],
]
],
];
Output

• Home
• About
• Departments
o Software Department
o Civil Department
o Electrical Department

Assignment Submission Policy:

• Please note that, when you submit your assignment’s file, create a folder with
your full name like this “G-firstname-midname-lastname” and zip it twice.
Note: G: is your group A or B

• The zipped project folder should be as follows:


 G-first_name-middle_name-last_name
 array.php
 string.php
 table.php
 menu.php
 utilities.php
Page 3 of 3

You might also like