How can arrays be used instead of numbered variables for better organization in PHP?
Using arrays instead of numbered variables in PHP can help improve organization by grouping related data together. This can make the code more readable and maintainable, especially when dealing with a large number of variables. By storing related values in an array, you can easily loop through them, access specific values using keys, and pass them around as a single unit.
// Using arrays for better organization
$user = [
'name' => 'John Doe',
'age' => 30,
'email' => 'john.doe@example.com'
];
// Accessing values from the array
echo $user['name']; // Output: John Doe
echo $user['age']; // Output: 30
echo $user['email']; // Output: john.doe@example.com