1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Array Question

Discussion in 'PHP' started by shortcut, Jan 28, 2010.

  1. #1
    Hi

    I have a doubt. Please help me if you know the answer

    
    Array
    (
        [status] => Array
            (
                [result] => Array
                    (
                        [accts] => Array
                            (
                                [0] => Array
                                    (
                                        [domain] => abc.com
                                        [user] => abccom
                                    )
    
                                [1] => Array
                                    (
                                        
                                        [domain] => cdf.com
                                        [user] => cdfcom
                                    )
                         )
             )
    
            )
    
    )
    
    
    
    
    
    PHP:

    This is an array $result

    I want to make a table like this

    Domain : User
    abc.com abccom
    cdf.com cdfcom

    This may be simple. But I am too confused with some other result and therefore my brain isn't working

    Anyone know the answer ?





    ..
     
    shortcut, Jan 28, 2010 IP
  2. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try the following code making the array data properly structured.

    
    
    $arr = Array
    (
        [status] => Array
            (
                [result] => Array
                    (
                        [accts] => Array
                            (
                                [0] => Array
                                    (
                                        [domain] => abc.com
                                        [user] => abccom
                                    )
    
                                [1] => Array
                                    (
                                       
                                        [domain] => cdf.com
                                        [user] => cdfcom
                                    )
                         )
             )
    
            )
    
    );
    
    
    foreach($arr[status][result][accts] as $k=>$v) {
    
            echo "Domain: ".$v[domain]."<br>";
            echo "User:" .$v[user];
    }
    
    
    PHP:
     
    HivelocityDD, Jan 28, 2010 IP
  3. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #3
    $ceva = Array('status' => Array('result' => Array('accts' => Array('0' => Array('domain' => 'abc.com','user' => 'abccom'),'1' => Array('domain' => 'cdf.com', 'user' => 'cdfcom')))));
             
    
    
    $cv = $ceva['status']['result']['accts'];
    
    foreach ($cv as $cv) {
    	print "Domain : $cv[domain] User $cv[user]";
    }
    PHP:
     
    crivion, Jan 28, 2010 IP