Using the Power of In-Built Controls
Using the Power of In-Built Controls
Welcome back! You've journeyed through crafting custom functions, mastering parameter handling, tracking variable scopes, and even exploring recursion. Today, we are going to tap into the powerful built-in functions that PHP offers. These functions are like advanced tools that help us execute common tasks effectively and efficiently. Are you excited to see what these functions can do for us? Let’s dive in!
What You'll Learn
In this unit, we will focus on how built-in functions in PHP can significantly simplify our code. By the end of this unit, you'll understand how to:
- Use array-related functions to manipulate arrays.
- Count elements, shift elements, and reverse arrays.
- Find maximum values in associative arrays.
To give you a preview, consider this detailed example:
Defining and Printing the Array
Here, the print_r function is employed to display the contents of the array, providing a quick and readable overview of the planets array.
Output:
Removing the Last Element
The array_pop function removes the last element from the array as displayed in the output.
Output:
Removing the First Element
On the other hand the array_shift function is used to eliminate the first element from the array.
Output:
Reversing the Array
