What are the differences between array handling in PHP compared to languages like C/++/Java?
In PHP, arrays are dynamic and do not require a fixed size declaration like in C/++/Java. PHP arrays can hold different data types in the same array, unlike in C/++/Java where arrays are homogeneous. PHP arrays are associative by default, allowing for key-value pairs, whereas in C/++/Java, arrays are typically indexed by integers.
// Creating an associative array in PHP
$person = array(
'name' => 'John',
'age' => 30,
'city' => 'New York'
);
// Accessing values in the PHP array
echo $person['name']; // Output: John
echo $person['age']; // Output: 30
echo $person['city']; // Output: New York