Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 07-07-2009
Member
 
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.
Reply With Quote
  #2  
Old 07-07-2009
Member
 
Join Date: May 2008
Posts: 2,293
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.
Reply With Quote
  #3  
Old 07-07-2009
Member
 
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
Reply With Quote
  #4  
Old 07-07-2009
Member
 
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 ", ";
}
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Echo array output in php?"
Thread Thread Starter Forum Replies Last Post
Output the contents of a PHP Array Jesus-Ernesto Software Development 3 27-01-2010 09:52 PM
Assigning an array to an array MACE Software Development 3 18-11-2009 05:19 PM
What is Echo? What is the difference between Echo and Print statement in PHP? Preetish Software Development 3 05-09-2009 01:41 PM
C++ Output 2D array? Laler Software Development 4 31-03-2009 02:36 PM
Set colors in echo revolucioncg Software Development 3 14-02-2009 09:53 PM


All times are GMT +5.5. The time now is 02:59 AM.