My question is : is there a function that return next object in array (with array and current object param) ? Can you help me to code the best way ?
function get_next($array, $currentObject) {
.... ?
return $nextObject;
}
My question is : is there a function that return next object in array (with array and current object param) ? Can you help me to code the best way ?
function get_next($array, $currentObject) {
.... ?
return $nextObject;
}
Here is my code, this
for($i = 0; $i < count($array) && $array[i] != $currentObject; $i++);
I would not put this into function at all, I would put it were I am calling that function but here is your function:
function get_next($array, $currentObject) {
for($i = 0; $i < count($array) && $array[i] != $currentObject; $i++);
return array[$i];
}
Simple linear and works in any occasion.