Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MervinPraison/b99c230c387bfe5a93ec8591c41f3138 to your computer and use it in GitHub Desktop.
Save MervinPraison/b99c230c387bfe5a93ec8591c41f3138 to your computer and use it in GitHub Desktop.
Comp function to sort PHP Array by Bible Verses (Scripture Books)
function scripturesort($a, $b) {
if ($a == $b) {return 0;}
$order=array("Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalm", "Proverbs", "Ecclesiastes", "Song of Solomon", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi", "Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation");
$fa = $a;
$fb = $b;
preg_match('/^..(.+?)\b/', $a, $matches);
$a = trim(substr($matches[0],0,4));
preg_match('/^..(.+?)\b/', $b, $matches);
$b = trim(substr($matches[0],0,4));
similar_text($a, $b, $p);
if($p > 75) {
preg_match('/(.+?)([\d]+)/', $fa, $matches);
$na = intval($matches[2]);
preg_match('/(.+?)([\d]+)/', $fb, $matches);
$nb = intval($matches[2]);
if($na == $nb) {
preg_match('/(.+?)([\d]+).*?:([\d]+)/', $fa, $matches);
$n2a = intval($matches[3]);
preg_match('/(.+?)([\d]+).*?:([\d]+)/', $fb, $matches);
$n2b = intval($matches[3]);
return ($n2a < $n2b) ? -1 : 1;
} else
return ($na < $nb) ? -1 : 1;
}
$position = key(preg_grep('/^'.$a.'(.*)\b/', $order));
$position2 = key(preg_grep('/^'.$b.'(.*)\b/', $order));
if ($position2!==false && $position!==false) {return ($position < $position2) ? -1 : 1;}
if($position!==false) {return -1;}
if($position2!==false) {return 1;}
return ($a < $b) ? -1 : 1;
}
usort($scriptures, 'scripturesort');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment