Move if ( is_array( $value ) && !$dupes ) { up to else block after the first !is_arra...