What is the difference between an array and a function in PHP?

An array in PHP is a data structure that can hold multiple values under a single variable name, allowing for easy access and manipulation of data. On the other hand, a function in PHP is a block of code that performs a specific task and can be called multiple times throughout the program. To differentiate between an array and a function in PHP, remember that an array stores data while a function executes a specific task. Arrays are accessed by their index values, while functions are called by their names followed by parentheses. It is important to understand the distinction between the two in order to effectively organize and manage your code.

// Example of an array in PHP
$fruits = array("apple", "banana", "orange");

// Example of a function in PHP
function greet() {
    echo "Hello, World!";
}

// Accessing array elements
echo $fruits[0]; // Output: apple

// Calling a function
greet(); // Output: Hello, World!