Hello everyone, today I would like to show you two different ways to display memory allocation of array elements. First, way is to use "var_dump" and second one is to use "print_r" method to print your memory map of array elements with their indexes. Now, lets get started!!
Using "var_dump"
<?php $months=array('jan','feb','mar','apr'); var_dump($months); ?>
If you use var_dump method it will print index no. of an array plus total char in a string of an array element. Your output should be like this
Output -
array(4){[0]=>string(3) "jan"
[1]=>string(3) "feb"
[2]=>string(3) "mar"
[3]=>string(3) "apr" }
Using "print_r"
<?php $months=array('jan','feb','mar','apr'); print_r($months); ?>
On the other hand if you use print_r method it will print index no. of an array with its associating array element. It's looks much easy and simple as compared with var_dump menthod and personally I like print_r much but you can use both var_dump and print_r depending upon your choice.Your output should be like this
Output -
Array
( [0]=>jan
[1]=>feb
[2]=>mar
[3]=>apr
)
If you like this post please do share, give your views, feedback and suggestions and mention us in comments. Thank You!!
0 comments:
Post a Comment