get key and value from GET in php

For some specific purposes you may want to know the current key of your array without going on a loop. In this case you could do the following:

echo key($array) . ' = ' . current($array);

The following functions are not very well known but can be pretty useful in very specific cases:

key($array);     //Returns current key
reset($array);   //Moves array pointer to first record
current($array); //Returns current value
next($array);    //Moves array pointer to next record and returns its value
prev($array);    //Moves array pointer to previous record and returns its value
end($array);     //Moves array pointer to last record and returns its value


<?php foreach($array as $text => $url): ?>
    <a href="<?php echo $url; ?>"><?php echo $text; ?></a>
<?php endforeach; ?>

$array = array(
    'SOA' => '',
    'Delhijurix' => ''

foreach($array as $title => $url){
    echo '<a href="' . $url . '">' . $title . '</a>';

Leave a Reply