0
0
PHPprogramming~15 mins

Case conversion functions in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
Case conversion functions
📖 Scenario: You are working on a simple text processing tool that changes the case of words. This is useful when you want to standardize names or titles in a list.
🎯 Goal: Build a PHP script that converts a list of words to uppercase, lowercase, and capitalized forms using PHP's case conversion functions.
📋 What You'll Learn
Create an array of words with exact values
Create a variable to hold the number of words
Use a for loop to convert each word to uppercase and store in a new array
Print the original array and the uppercase array
💡 Why This Matters
🌍 Real World
Changing the case of text is common in data cleaning, formatting user input, or preparing text for display.
💼 Career
Many programming jobs require manipulating strings and arrays, especially for web development and data processing.
Progress0 / 4 steps
1
Create the initial array of words
Create an array called words with these exact values: 'apple', 'Banana', 'Cherry', 'date', 'Elderberry'.
PHP
Need a hint?

Use $words = [ ... ]; to create the array with the exact words.

2
Create a variable for the number of words
Create a variable called count and set it to the number of elements in the $words array using the count() function.
PHP
Need a hint?

Use count($words) to get the number of words.

3
Convert words to uppercase using a for loop
Create an empty array called upperWords. Use a for loop with the variable i from 0 to $count - 1. Inside the loop, convert $words[i] to uppercase using strtoupper() and store it in upperWords[i].
PHP
Need a hint?

Use strtoupper() to convert each word to uppercase inside the loop.

4
Print the original and uppercase arrays
Use print_r() to print the $words array with the label "Original words:". Then print the $upperWords array with the label "Uppercase words:".
PHP
Need a hint?

Use print_r() to display arrays with labels.