Sunday, December 29, 2013

[php] php count array size or length

For example, i have an array named $photofield ,
i would like to know the size of that:

        $photofield   = array("p_1_1","p_1_2","p_1_3","p_1_4",
                                "p_2_1","p_2_2","p_2_3","p_2_4",
                                "p_3_1","p_3_2","p_3_3","p_3_4",
                                "p_4_1","p_4_2","p_4_3","p_4_4",
                                "p_5_1","p_5_2","p_5_3","p_5_4",
                                "p_6_1","p_6_2","p_6_3","p_6_4",
                                "p_7_1","p_7_2","p_7_3","p_7_4",
                                "p_8_1","p_8_2","p_8_3","p_8_4",
                                "p_9_1","p_9_2","p_9_3","p_9_4",      
                                "p_1_1_t","p_1_2_t","p_1_3_t","p_1_4_t",
                                "p_2_1_t","p_2_2_t","p_2_3_t","p_2_4_t",
                                "p_3_1_t","p_3_2_t","p_3_3_t","p_3_4_t",
                                "p_4_1_t","p_4_2_t","p_4_3_t","p_4_4_t",
                                "p_5_1_t","p_5_2_t","p_5_3_t","p_5_4_t",
                                "p_6_1_t","p_6_2_t","p_6_3_t","p_6_4_t",
                                "p_7_1_t","p_7_2_t","p_7_3_t","p_7_4_t",
                                "p_8_1_t","p_8_2_t","p_8_3_t","p_8_4_t",
                                "p_9_1_t","p_9_2_t","p_9_3_t","p_9_4_t"); 
You can use the  count() function in php ,
for more information, please read php official website :
http://www.php.net/count

For my case,
I use the php value $photofield which is stored the array values as the parameter in count() function,
and than store in the value $photos.

$photos = count($photofield);
To know the size of the array, you can print it by using echo:

echo $photo;

and the output result would be : 72


Reference:
http://www.php.net/count

No comments :

Post a Comment