I was reading some Wordpress plugin code when I come across this function:
function bp_nouveau_hook( $pieces = array() ) {
if ( ! $pieces ) {
return;
}
$bp_prefix = reset( $pieces );
if ( 'bp' !== $bp_prefix ) {
array_unshift( $pieces, 'bp' );
}
$hook = join( '_', $pieces );
/**
* Fires inside the `bp_nouveau_hook()` function.
*
* @since BuddyPress 3.0.0
*/
do_action( $hook );
}
As far as I understand you use reset()
when the array's pointer could be changed by functions such as prev()
or next()
etc. But by reading this code, I don't see any chance the $pieces
array parameter's pointer could be changed. Why then use reset()
here?