Skip to content

Instantly share code, notes, and snippets.

@HoangPV
Created July 25, 2017 14:59
Show Gist options
  • Save HoangPV/6506b01fb1e20359b32e9478610e62a3 to your computer and use it in GitHub Desktop.
Save HoangPV/6506b01fb1e20359b32e9478610e62a3 to your computer and use it in GitHub Desktop.
Take a string, then for every words we reverse the order of character.
<?php
echo strRevCha("Take a string, then for every words we reverse the order of character.");
/**
* Take a string, then for every words we reverse the order of character.
*
* @param String $str a string
* @return String|null $strOutput
* @author Phan Vu Hoang <vu-hoang.phan@ekino.com>
*/
function strRevCha($str) {
$strOutput = [];
$strAr = explode(' ', $str);
foreach ( $strAr as $s) {
$strOutput[] = strrev($s);
}
return implode(" ", $strOutput);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment