Jump to content

Retrieve data from arrays


me1000

Recommended Posts

so here is the array (which holds an array for each value)

 

$data = array( 
array('name'=>'Title 1','number'=>"$intEnrolled") 
,array('name'=>'Title 2','number'=>"$intCompleted") 
,array('name'=>'Title 3','number'=>"$intExpired") 
,array('name'=>'Title 4','number'=>"$intProgress")
); 

 

 

Now I need to get every value from the array...

 

so I need like a foreach loop or something,

 

but I need to get both values ('name' and 'number')

 

I just dont know exactly how to do it,

 

foreach (){
echo 'name'.' IS '.'number';
}

which would display as

 

Title 1 IS $intEnrolled

Title 2 IS $intCompleted

etc...

 

 

I hope this makes since,

 

Thanks,

Link to comment
https://forums.phpfreaks.com/topic/94102-retrieve-data-from-arrays/
Share on other sites

<?
$data = array( 
array('name'=>'Title 1','number'=>$intEnrolled) 
,array('name'=>'Title 2','number'=>$intCompleted) 
,array('name'=>'Title 3','number'=>$intExpired) 
,array('name'=>'Title 4','number'=>$intProgress)
);
foreach($data as $val){
echo $val['name'].'  IS '. $val['number'].'<br/>';
}
?>

 

try and you dont need the "" on your var..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.