What is the correct syntax for accessing nested arrays in PHP?
When accessing nested arrays in PHP, you need to use multiple square brackets to traverse through the nested levels. Each set of square brackets represents accessing a level deeper in the array structure. For example, if you have an array $arr that contains another array as one of its elements, you would access the nested array like this: $nestedElement = $arr['key']['nestedKey'].
// Example of accessing a nested array in PHP
$arr = array(
'key' => array(
'nestedKey' => 'value'
)
);
$nestedElement = $arr['key']['nestedKey'];
echo $nestedElement; // Output: value
Related questions
-
cookies user authentication PHP
-
PHP form validation regular expressions
-
PHP tab string