Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1737 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Array Question

Thread title: Array Question
     
    Thread tools Search this thread Display Modes  
Prev Previous Post   Next Post Next
10-18-2012, 03:35 PM
#3
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

Ah thanks. I studied your code and came up with something very similar:

PHP Code:
    // format $_POST into a multi-dimensional array
    
foreach($_POST as $key => $value) {
        
preg_match('/^([0-9]+)-([A-z]+)-([0-9]+)$/'$key$matches);

        
// build new parent key
        
$parent_key $matches[1] . '-'.$matches[3];

        
// build new key
        
$newkey $matches[2];

        
// if empty value delete key else recreate
        
if(!$value)
            unset(
$_POST[$key]);
        else
            
$sorted[$parent_key][$newkey] = $value;

    }

    
// reformat some keys and values
    
foreach ($sorted as $array_key => $array) {

        
$hour     NULL;
        
$minute NULL;
        
$second NULL;

        foreach (
$array as $key => $value) {

            if ((
$key == "hr") & ($value 0)) {
                
$hour $value;
                unset(
$sorted[$array_key][$key]);
            }
            if ((
$key == "min") & ($value 0)) {
                
$minute $value;
                unset(
$sorted[$array_key][$key]);
            }
            elseif ((
$key == "sec") & ($value 0)) {
                
$second $value;
                unset(
$sorted[$array_key][$key]);
            }

        }

        
// convert hr:min:sec to seconds
        
if (isset($hour) && isset($minute) && isset($second)) {

            
$formatted $convert->time($hour"hour""second") + $convert->time($minute"minute""second") + $second;
            
$sorted[$array_key]['seconds'] = $formatted;

        }

    } 

Reply With Quote
     


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed