getting the first key of an array

I always have the problem with having an array that only has one key, and I want that key and the value, I used to use something like: foreach($arr as $key => $val){ $this->key = $key; $this->val = $val; } which is dumb, here is a much better way:

$arr = array('some_key_with_meaning' => 1);
reset($arr);
$key = key($arr);
$val = $arr[$key];

to get the last key and value:
end($arr);
$key = key($arr);
$val = $arr[$key];

1 2 Next »

20 Total