www.webdeveloper.com
Results 1 to 6 of 6

Thread: php array

  1. #1
    Join Date
    Jul 2005
    Location
    faisalabad, punjab, pakistan
    Posts
    241

    php array

    hi, i have following array and the output is attached as attachment.

    i need to altert this output so that it prints next person name in BY column, so the new output will be like

    HTML Code:
    Rubab Admani	 Pending Review	        Farrukh Mushtaq	08/Jan/2014 12:03 PM
    Farrukh Mushtaq	 Pending Assignment	Beatriz Artal	08/Jan/2014 16:11 PM
    Beatriz Artal	 In Progress	                Irfan Shafiq     	08/Jan/2014 16:48 PM
    thanks in advance.


    PHP Code:
    Array
    (
        [
    pendingReview] => Array
            (
                [
    by] => Rubab Admani
                
    [date] => 2014-01-08 12:03:45
            
    )

        [
    pendingAssignment] => Array
            (
                [
    by] => Farrukh Mushtaq
                
    [date] => 2014-01-08 16:11:21
            
    )

        [
    inProgress] => Array
            (
                [
    by] => Beatriz Artal
                
    [date] => 2014-01-08 16:48:27
            
    )

        [
    finalReviewing] => Array
            (
                [
    by] => Irfan Shafiq
                
    [date] => 2014-01-09 11:01:26
            
    )

        [
    readyToSubmit] => Array
            (
                [
    by] => Beatriz Artal
                
    [date] => 2014-01-09 13:37:26
            
    )


    Untitled.png

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    849
    Where is the "BY column"?

  3. #3
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    Your question is a little confusing but I think what you want is:
    PHP Code:
    <?php
    $arr 
    = Array
    (
        
    "pendingReview" => Array
        (
            
    "by" => "Rubab Admani",
            
    "date" => "2014 - 01 - 08 12:03:45"
        
    ),

        
    "pendingAssignment" => Array
        (
            
    "by" => "Farrukh Mushtaq",
            
    "date" => "2014 - 01 - 08 16:11:21"
        
    ),

        
    "inProgress" => Array
        (
            
    "by" => "Beatriz Artal",
            
    "date" => "2014 - 01 - 08 16:48:27"
        
    ),

        
    "finalReviewing" => Array
        (
            
    "by" => "Irfan Shafiq",
            
    "date" => "2014 - 01 - 09 11:01:26"
        
    ),

        
    "readyToSubmit" => Array
        (
            
    "by" => "Beatriz Artal",
            
    "date" => "2014 - 01 - 09 13:37:26"
        
    )

    );

    $display "";

    foreach(
    $arr AS $status => $info){
        
    preg_match_all("/[A-Z]?[a-z]+/",$status,$statusBits);
        
    $status implode(" ",$statusBits[0]);
        
    $status ucwords($status);
        
    $display str_replace("|nxtname|",$info['by'],$display);
        
    $display .= "{$info['by']}    {$status}    |nxtname|    {$info['date']}\n";
    }

    echo 
    $display;
    This outputs (I wasn't sure how you wanted to handle the last one, where there is no next person.):
    Code:
    Rubab Admani    Pending Review    Farrukh Mushtaq    2014 - 01 - 08 12:03:45
    Farrukh Mushtaq    Pending Assignment    Beatriz Artal    2014 - 01 - 08 16:11:21
    Beatriz Artal    In Progress    Irfan Shafiq    2014 - 01 - 08 16:48:27
    Irfan Shafiq    Final Reviewing    Beatriz Artal    2014 - 01 - 09 11:01:26
    Beatriz Artal    Ready To Submit    |nxtname|    2014 - 01 - 09 13:37:26

  4. #4
    Join Date
    Jan 2014
    Posts
    96
    Arrays can be used in many ways to store and organize data quickly and efficiently. It is one of the more useful data types available to any programming language.Arrays can most easily be described as an ordered list of elements. You can access the individual elements by referring to their index position within the array. The position is either specified numerically or by name.

  5. #5
    Join Date
    Jul 2005
    Location
    faisalabad, punjab, pakistan
    Posts
    241
    thanks! this is what i was looking for. thanks again!

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,518
    Another alternative might be to massage the array to dynamically add the "next" person to it:
    PHP Code:
    <?php
    $arr 
    = Array
    (
        
    "pendingReview" => Array
        (
            
    "by" => "Rubab Admani",
            
    "date" => "2014 - 01 - 08 12:03:45"
        
    ),

        
    "pendingAssignment" => Array
        (
            
    "by" => "Farrukh Mushtaq",
            
    "date" => "2014 - 01 - 08 16:11:21"
        
    ),

        
    "inProgress" => Array
        (
            
    "by" => "Beatriz Artal",
            
    "date" => "2014 - 01 - 08 16:48:27"
        
    ),

        
    "finalReviewing" => Array
        (
            
    "by" => "Irfan Shafiq",
            
    "date" => "2014 - 01 - 09 11:01:26"
        
    ),

        
    "readyToSubmit" => Array
        (
            
    "by" => "Beatriz Artal",
            
    "date" => "2014 - 01 - 09 13:37:26"
        
    )

    );

    $keys array_keys($arr);
    foreach(
    $keys as $ix => $key) {
        if(isset(
    $keys[$ix+1])) {
            
    $arr[$key]['next'] = $arr[$keys[$ix+1]]['by'];
        }
    }
    print_r($arr);
    Output:
    Code:
    Array
    (
        [pendingReview] => Array
            (
                [by] => Rubab Admani
                [date] => 2014 - 01 - 08 12:03:45
                [next] => Farrukh Mushtaq
            )
    
        [pendingAssignment] => Array
            (
                [by] => Farrukh Mushtaq
                [date] => 2014 - 01 - 08 16:11:21
                [next] => Beatriz Artal
            )
    
        [inProgress] => Array
            (
                [by] => Beatriz Artal
                [date] => 2014 - 01 - 08 16:48:27
                [next] => Irfan Shafiq
            )
    
        [finalReviewing] => Array
            (
                [by] => Irfan Shafiq
                [date] => 2014 - 01 - 09 11:01:26
                [next] => Beatriz Artal
            )
    
        [readyToSubmit] => Array
            (
                [by] => Beatriz Artal
                [date] => 2014 - 01 - 09 13:37:26
            )
    
    )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles