bb_get_common_parts

The BuddyPress bb get common parts function.

Description

bb_get_common_parts( (constant) $string1 = false, (constant) $string2 = false, (string) $delimiter = '', (constant) $reverse = false ); 

Parameters (4)

0. $string1 — Optional. (constant) => false
The string1.
1. $string2 — Optional. (constant) => false
The string2.
2. $delimiter — Optional. (string) => ''
The delimiter.
3. $reverse — Optional. (constant) => false
The reverse.

Usage

  1. if ( !function_exists( 'bb_get_common_parts' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-core.php'; 
  3.  
  4. // The string1. 
  5. $string1 = false; 
  6.  
  7. // The string2. 
  8. $string2 = false; 
  9.  
  10. // The delimiter. 
  11. $delimiter = ''; 
  12.  
  13. // The reverse. 
  14. $reverse = false; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bb_get_common_parts($string1, $string2, $delimiter, $reverse); 
  18.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-includes/functions.bb-core.php  
  1. function bb_get_common_parts($string1 = false, $string2 = false, $delimiter = '', $reverse = false) { 
  2. if (!$string1 || !$string2) { 
  3. return false; 
  4.  
  5. if ($string1 === $string2) { 
  6. return $string1; 
  7.  
  8. $string1_parts = explode( $delimiter, (string) $string1 ); 
  9. $string2_parts = explode( $delimiter, (string) $string2 ); 
  10.  
  11. if ($reverse) { 
  12. $string1_parts = array_reverse( $string1_parts ); 
  13. $string2_parts = array_reverse( $string2_parts ); 
  14. ksort( $string1_parts ); 
  15. ksort( $string2_parts ); 
  16.  
  17. $common_parts = array(); 
  18. foreach ( $string1_parts as $index => $part ) { 
  19. if ( isset( $string2_parts[$index] ) && $string2_parts[$index] == $part ) { 
  20. $common_parts[] = $part; 
  21. } else { 
  22. break; 
  23.  
  24. if (!count($common_parts)) { 
  25. return false; 
  26.  
  27. if ($reverse) { 
  28. $common_parts = array_reverse( $common_parts ); 
  29.  
  30. return join( $delimiter, $common_parts );