Advertisement
Guest User

Untitled

a guest
May 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. <?php
  2.  
  3. $string1 = '1: 2, 3';
  4. $string2 = '1: 2, 3; 4: 5, 6';
  5.  
  6. function revert(string $string) {
  7.  
  8. $array = explode('; ', $string);
  9.  
  10. foreach ($array as $x => $entry) {
  11.  
  12. $subarray = explode(': ', $entry);
  13.  
  14. foreach ($subarray as $i => $subentry) {
  15.  
  16. $substring = explode(', ', $subentry);
  17. $substringReverse = array_reverse($substring);
  18. $subarray[$i] = implode(' ', $substringReverse);
  19. }
  20.  
  21. $array[$x] = implode(': ', $subarray);
  22. }
  23.  
  24. return implode('; ', $array);
  25. }
  26.  
  27. $result = revert($string1);
  28. print_r($result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement