How can the use of arrays in PHP improve the efficiency and readability of code compared to using individual variables?
Using arrays in PHP can improve efficiency and readability by allowing you to store and access multiple related values using a single variable. This can reduce the number of individual variables needed in your code, making it more organized and easier to manage. Additionally, arrays provide built-in functions for sorting, searching, and manipulating data, which can streamline your code and make it more efficient.
// Using arrays to store and access multiple related values
$student1 = array("name" => "John", "age" => 20, "grade" => "A");
$student2 = array("name" => "Jane", "age" => 22, "grade" => "B");
// Accessing values from the arrays
echo $student1["name"]; // Output: John
echo $student2["age"]; // Output: 22