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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -