When using the code below in a function ($floor & $lift are passed in but I've added them here for demonstration) I'm getting an Notice: Undefined offset: 20 on the last return statement.
The last return is the mean that's mean to be used in this example but why am I getting the Notice: Undefined offset: 20? If I'm not mistake (which I clearly am) the array_key_exists() function should be preventing this? I've also tried it with isset() with no success.
$floor = 20;
$lift = false;
$moving = array(
"no_lift" => array(
1 => 0,
2 => 13,
3 => 17,
4 => 20
),
"lift" => array(
1 => 0,
2 => 10,
3 => 10,
4 => 20
)
);
switch ( $lift ) {
case true:
return ( isset( $moving["lift"][ $floor ] ) ? $moving["lift"][ $floor ] : $moving["lift"][ end( $moving["lift"] ) ] );
break;
case false:
return ( array_key_exists( $floor, $moving["no_lift"] ) ? $moving["no_lift"][ $floor ] : $moving["no_lift"][ end( $moving["no_lift"] ) ] );
break;
}
end( $moving["no_lift"] )will be20. Which doesn't exist.array_key_existsfunction is good only for associative arrays. For sequential arrays usecountfunction.