Displaying the element in two dimensional array with caption

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 .

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.