Results 1 to 4 of 4

Thread: Echo array output in php?

  1. #1
    Join Date
    Apr 2009
    Posts
    79

    Echo array output in php?

    I am using array in my program to store data value.

    $employee= array(
    "1" => array("age"=>"36", "no"=>"3"),
    "2" => array("age"=>"45", "no"=>"4"),
    );

    How to get output with array of two value or echo array values in php? I need to display two employee 1 and 2 with there age and no.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Echo array output in php?

    Code:
    print_r($myarray);
    This will display all the items in array for example: employee no and employee age. It will display all the items with listing in the array with multi-dimensional arrays. This will only use debugging purposes or as testing method.

  3. #3
    Join Date
    Dec 2008
    Posts
    177

    Re: Echo array output in php?

    Follow this example to use echo array values in php.

    Code:
    $color[0]="yellow";
    $color[1]="white";
    $color[2]="black";
    
    To echo, simply do:
    
    echo $color[0]; // outputs yellow
    echo $color[1]; // outputs white
    echo $color[2]; // outputs black
    
    Or you can a declare a variable for each value as follows:
    
    $colorone=$color[0];
    $colortwo=$color[1];
    $colorthree=$color[2];
    
    And then echo the variable as follows:
    
    echo $colorone; // outputs yellow
    echo $colortwo; // outputs  white
    echo $colorthree; // outputs black

  4. #4
    Join Date
    Jan 2009
    Posts
    199

    Re: Echo array output in php?

    Code:
    foreach($employee as $item) {
    $y = 0;
    while($y < count($item)) {
    echo $item[y];
    $y++;
    if($y < count($item)) {
    echo ", ";
    }
    }
    }

Similar Threads

  1. Output the contents of a PHP Array
    By Jesus-Ernesto in forum Software Development
    Replies: 3
    Last Post: 27-01-2010, 09:52 PM
  2. Assigning an array to an array
    By MACE in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 05:19 PM
  3. Replies: 3
    Last Post: 05-09-2009, 01:41 PM
  4. C++ Output 2D array?
    By Laler in forum Software Development
    Replies: 4
    Last Post: 31-03-2009, 02:36 PM
  5. Set colors in echo
    By revolucioncg in forum Software Development
    Replies: 3
    Last Post: 14-02-2009, 09:53 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,713,556,669.72220 seconds with 16 queries