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

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

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

Leave a Reply