0
0
PHPprogramming~20 mins

Why PHP powers most of the web - See It in Action

Choose your learning style9 modes available
Why PHP Powers Most of the Web
📖 Scenario: Imagine you are a web developer learning why PHP is so popular for building websites. You want to create a simple PHP script that shows some reasons why PHP powers most of the web.
🎯 Goal: You will build a PHP script that stores reasons why PHP is popular in an array, filters the reasons based on a minimum length, and then displays the filtered reasons on the web page.
📋 What You'll Learn
Create an array called $reasons with 5 exact reasons as strings
Create a variable called $minLength set to 15
Use a foreach loop to create a new array $filteredReasons containing only reasons with length greater than or equal to $minLength
Print each filtered reason inside an HTML <li> element within an unordered list
💡 Why This Matters
🌍 Real World
PHP is widely used to build websites and web applications. Filtering and displaying data dynamically is a common task in web development.
💼 Career
Understanding PHP basics like arrays, loops, and string functions is essential for backend web development jobs.
Progress0 / 4 steps
1
Create the reasons array
Create an array called $reasons with these exact strings: 'Easy to learn', 'Wide hosting support', 'Large community', 'Fast development', 'Open source'.
PHP
Need a hint?

Use the PHP array syntax with square brackets and separate strings with commas.

2
Set the minimum length variable
Create a variable called $minLength and set it to 15.
PHP
Need a hint?

Use the assignment operator = to set the value.

3
Filter reasons by length
Use a foreach loop with variable $reason to iterate over $reasons. Inside the loop, add $reason to a new array called $filteredReasons only if its length is greater than or equal to $minLength. Use the strlen() function to get the length of the string.
PHP
Need a hint?

Initialize $filteredReasons as an empty array before the loop.

4
Display the filtered reasons
Use a foreach loop with variable $reason to iterate over $filteredReasons. Inside the loop, print each $reason inside an HTML <li> element. Wrap the list items inside an unordered list <ul>.
PHP
Need a hint?

Use echo to print HTML tags and list items.