Displaying the element in two dimensional array with caption
Displaying the element in two dimensional array with caption
In One dimensional array it is easy to display the element with caption like other variables.
- But many time we have an array with more than one dimension, but in two dimensional array complex parsing is required. to avoid this we use { } braces.
here,complex parsing syntax is required. echo “Contents: {$arr[1][2]}” would’ve worked.
Example:
$numarr = array(1,2,3);
$arr = array(”a”,”b”,”c”,$numarr);
From, the above Statement We wants to display the 2nd element in the $numarr using $arr
echo $arr[3][1]; // Now it displays 2.
But We need to display with some caption like
echo “Content in 2nd position of numarr is $arr[3][1]”;
It displays Content in 2nd position of numarr is Array[1] .
here, the value 2 is not return here. to avoid this we can use { } symbol.
echo “Content in 2nd position of numarr is {$arr[3][1]}”;
Now It displays Content in 2nd position of numarr is 2 .
