Increment index of an array in PHP -
i want find element placed right after $input
seems type of index not int , because of can not mathematical operations on .
$index = array_search($input,$tmp); $index += 1 ; $hold = $tmp[$index]; echo $hold;
don't on think it, use array_values()
:
$index = array_search($input, array_values($tmp)); $index += 1; $hold = array_values($tmp)[$index]; echo $hold;
you want checking make sure key returned array_search()
, check next index isset()
.
$vals = array_values($tmp); $index = array_search($input, $vals); if($index !== false && isset($vals[++$index])) { $hold = $vals[$index]; // has incremented ++$index echo $hold; }
Comments
Post a Comment