Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@flyingluscas
Created November 5, 2016 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyingluscas/56917c84ac61b8ff5457f7a3d69157ab to your computer and use it in GitHub Desktop.
Save flyingluscas/56917c84ac61b8ff5457f7a3d69157ab to your computer and use it in GitHub Desktop.
Example
$text = '10,15,20,25,30,22,14,33';

$sets = array_map(function ($values) {
    return sprintf('/(%s)/', implode('|', $values));
}, [
    range(10, 15),
    range(20, 25),
    range(30, 35),
]);

$output = preg_replace($sets, [
    'Alface', 'Beringela', 'Couve',
], $text);

echo $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment