What are the advantages and disadvantages of using associative arrays in PHP?
Associative arrays in PHP allow for storing key-value pairs, making it easier to access and manipulate data. However, they can be slower than indexed arrays when dealing with a large amount of data. Additionally, associative arrays can be more memory-intensive compared to indexed arrays.
// Example of using an associative array in PHP
$student = array(
'name' => 'John Doe',
'age' => 20,
'grade' => 'A'
);
// Accessing values from the associative array
echo $student['name']; // Output: John Doe
echo $student['age']; // Output: 20
echo $student['grade']; // Output: A