You appear to be a bot. Output may be restricted
Description
Return the array[index] or array->index (for an object) or a default value if not setNote: This code is slightly more efficient with the default being assigned in the else than when there is just one assignment of $value = $default right at the start where slightly more is 2 or 3 microseconds – measured on a laptop.
Usage
bw_array_get( $array, $index, $default );
Parameters
- $array
- ( mixed ) required –
- $index
- ( mixed ) required –
- $default
- ( mixed ) optional –
Returns
voidSource
File name: oik-bwtrace/includes/bwtrace.phpLines:
1 to 22 of 22
function bw_array_get( $array, $index, $default=NULL ) { if ( isset( $array ) ) { if ( is_array( $array ) ) { if ( isset( $array[$index] ) || array_key_exists( $index, $array ) ) { $value = $array[$index]; } else { $value = $default; } } elseif ( is_object( $array ) ) { if ( property_exists( $array, $index ) ) { $value = $array->$index; } else { $value = $default; } } else { $value = $default; } } else { $value = $default; } return( $value ); }View on GitHub View on Trac