Results 1 to 4 of 4

Thread: Recovery of certain values in an PHP array

  1. #1
    Join Date
    Nov 2008
    Posts
    1,185

    Recovery of certain values in an PHP array

    I have a table containing several groups of numbers such
    3 4 5 6 7 8 9 15 16 17 18 19 20 52 53 54 55 56 57 58

    I get the first and last element of each group of numbers in a new table. In my example, I therefore in my new table 3 9 15 20 52 58

    That is what I wrote but it does not work.

    PHP Code:
    $tab1 = array (); 
      
    $i 1
      
    $j 0
      
    $debut1 current ($tab); // first element of my first table 
      
    $val $debut1
      
    $val2 $val $i
      foreach (
    $tab as $value
      { 
      
    $val2 $val $i
      
    $val3 next ($ tab); 
      if (
    $val3 $val2
      { 
      
    $i++; 
      
    $tab1 $j ] = $val
      } 
      else 
      { 
      
    $j++; 
      
    $tab1 $j ] =prev $tab ); 
      
    $val current ($tab); 
      }
      } 

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Recovery of certain values in an PHP array

    These numbers come from where? you need to do this for what? I ask this because there are several ways to do so I prefer to ask more details to make it match what you need

  3. #3
    Join Date
    May 2008
    Posts
    685

    Re: Recovery of certain values in an PHP array

    Quote Originally Posted by windows_user View Post
    I have a table containing several groups of numbers such
    3 4 5 6 7 8 9 15 16 17 18 19 20 52 53 54 55 56 57 58
    How groups are defined and identified?

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Recovery of certain values in an PHP array

    Just try this. I suppose it should definitely work.

    PHP Code:
    $tab = array (); 
      
    $tab [0] ='3 4 5 6 7 8 9 '
      
    $tab [1] ='15 16 17 18 19 20 '
      
    $tab [2] ='52 53 54 55 56 57 58 '

      for (
    $i 0$i <count ($tab); $i++) 
      { 
              
    $vals = array (); 
              
    $vals explode ""$tab [$i]); 
              
    $val1 $vals [0]; 
              
    $val2 $vals [count ($vals) - 1]; 

              
    // Val1 and val2 contain here the first and last value 
      


Similar Threads

  1. W32 registry values are not getting matched by the default values
    By Angrzej in forum Networking & Security
    Replies: 5
    Last Post: 19-05-2011, 12:23 PM
  2. Problem writing creating recovery disc in Recovery Manager
    By SajalSOFT in forum Windows Software
    Replies: 6
    Last Post: 11-09-2010, 02:24 AM
  3. Replies: 7
    Last Post: 13-08-2010, 10:39 AM
  4. Problem in creating array from string values
    By Cedric in forum Software Development
    Replies: 4
    Last Post: 19-01-2010, 05:48 PM
  5. Assigning an array to an array
    By MACE in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 05:19 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,460,178.25885 seconds with 16 queries