This repository contains PHP code examples and tasks for mastering array and string manipulation in PHP.
Create a PHP script that demonstrates string manipulation. Start by defining a string variable called $text
with the value "The quick brown fox jumps over the lazy dog." Then, write a PHP function that takes $text
as an argument to perform the following tasks:
- Convert the string to all lowercase.
- Replace "brown" with "red" in the string.
- Print the modified text.
In this task, you'll work with arrays. Create a PHP script that performs array manipulation. Begin by creating an array called $numbers
containing the numbers from 1 to 10. Then, write a PHP function that takes the $numbers
array as an argument to remove all even numbers from the array and print the resulting array.
This task focuses on sorting arrays. Create a PHP script that works with an array called $grades
containing the following values: 85, 92, 78, 88, 95. Write a PHP function that takes $grades
as an argument to sort the array in descending order and then print the sorted grades as an array.
In this task, you'll work with multidimensional arrays. Create a PHP script that deals with a multidimensional array called $studentGrades
, which stores the grades of three students. Each student has grades for three subjects: Math, English, and Science. Write a PHP function that takes $studentGrades
as an argument to calculate and print the average grade for each student.
For this task, create a PHP function called generatePassword($length)
that generates a random password of the specified length. The password should include lowercase letters, uppercase letters, numbers, and special characters (!@#$%^&*()_+). Write a PHP program that uses this function to generate a password with a length of 12 characters and then print the generated password.