I have an array:
$array=array(
"sdf"=>500,
"gsda"=>1000,
"bsdf"=>1500,
"bads"=>2000,
"iurt"=>2500,
"poli"=>3000
);
How can I get the name of the next key? For example if the current array is gsda
, I need bsdf
.
I have an array:
$array=array(
"sdf"=>500,
"gsda"=>1000,
"bsdf"=>1500,
"bads"=>2000,
"iurt"=>2500,
"poli"=>3000
);
How can I get the name of the next key? For example if the current array is gsda
, I need bsdf
.
If the pointer of
current()
is on the right key, @Thomas_Cantonnet is right and you want to usenext()
. If you did not iterate through the array via next(), you first have to go through the array to set the internal index pointer correctly:Now $next points to your current search-index and you can iterate over the rest via
next()
.use a combo of next and each to get both the key and value of the next item:
$keyvalueArray should now hold the next key and value as 'key' and 'value'
http://www.php.net/manual/en/function.each.php
you can use a
foreach
output
// in above function first argument is array in which key needs to be searched and 2nd argument is $key which is used to get next key so it means you must one existing key of associative array from you which you want to get next keys.
If pointer is not on this element, as other solutions assume, You can use
Should return the key corresponding to $next;