seo-asif / Mastering-PHP-Array-String

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mastering PHP Array and String Manipulation

This repository contains PHP code examples and tasks for mastering array and string manipulation in PHP.

Task 1: String Manipulation

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:

  1. Convert the string to all lowercase.
  2. Replace "brown" with "red" in the string.
  3. Print the modified text.

Task 2: Array Manipulation

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.

Task 3: Array Sorting

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.

Task 4: Multidimensional 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.

Task 5: Password Generator

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.

About


Languages

Language:PHP 100.0%