Advertisement
Guest User

Php_merge_array

a guest
Oct 31st, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2.  
  3. $arFirst = array('mama', 'papa', 'horse');
  4. $arSecond = array('class', 'grandma', 'keyboard');
  5.  
  6. $pairArray = array();
  7. $notPair = array();
  8.  
  9. $test = implode(" " , $arFirst);
  10. $testTwo = implode(" " , $arSecond);
  11.  
  12. function count_letter($x) {
  13.     $count = 0;
  14.     for ($i = 0; $i < strlen($x); $i++) {
  15.         if (strpos('euoaiy', $x[$i]) > -1) {
  16.             $count++;
  17.         }
  18.     }
  19.     return $count;
  20. }
  21.  
  22.  
  23.  
  24. if(count_letter($test) % 2 ===0) {
  25.     array_unshift($pairArray , $test);
  26.    
  27. }else {
  28.     array_unshift($notPair , $test);
  29.    
  30. }
  31.  
  32. if(count_letter($testTwo) % 2 ===0) {
  33.      array_unshift($pairArray , $testTwo);
  34.  
  35. }else {
  36.     array_unshift($notPair , $testTwo);
  37.    
  38. }
  39.  
  40. $res = array_merge($pairArray,$notPair);
  41. print_r($res);
  42.  
  43.    
  44.  
  45.  
  46.  
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement