Help:php array mix(like cross of math sets)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help:php array mix(like cross of math sets)

    HI, i need help with this.
    Code:
    <?php
    $main_array	=array('x','y');
    $some_array	=array('a','b');
    How can i get
    Code:
    $new_array=('ax','ay','bx','by');
    Someone please help me, the original main_array and some_array contain too much(50 each)data and they change hourly,
    So its impossible for me to do it manually, i need it done using php and i will use the new_array in a simple str_replace.
    All help will be appreciated.
    Last edited by Sifat3d; 17.03.12, 16:46. Reason: Tags

    #2
    PHP Code:
    $main_array = array('x','y');
    $some_array = array('a','b');
    $new_array = array();
    $t 0;
    for (
    $i 0$i <= count($some_array)-1$i++)
    {
       for (
    $a 0$a <= count($main_array)-1$a++)
       {
            
    $new_array[$t] =  $some_array[$i].$main_array[$a];
            
    $t++;
       }

    Comment


      #3
      actually the same code as posted by something else

      PHP Code:
      $main_array = array('x','y'); 
      $some_array = array('a','b'); 

      for (
      $i 0$i count($some_array); $i++) 
      {
          for (
      $k 0$k count($main_array); $k++) 
          {
              
      $new_array[] =  $some_array[$i].$main_array[$k]; 
          }
      }
      print_r($new_array); 
      Advertise your mobile site for FREE with AdTwirl

      Comment

      Working...
      X