Get the offset (index, array key) of an array in php

by cliper Monday, December 06, 2010 3:38 PM

$fruits = array(0 => “apple”,
                1 => “orange”,
                2 => “lemon”
);

foreach($fruits as $key => $fruit)
{
    printf(“%s is in index %s”, $fruit, $key);
}

Tags:

Code Snippets | PHP

Comments are closed

About the author

Author's PhotoI enjoy web developing and would like to share my thoughts of it.

Send mailE-mail me

Most comments

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar