Jump to content

Muliti dimensional Array question w/ Date


paruby

Recommended Posts

I know how to work w/ arrays when they are passed from say a POST, but can't seem to create one on my own...

 

I have 2 sets of variables.  I have a name and date, and want to print them.  I have basically:

 

$Name1 = "John";

$Date1 = "200802";  // Formatted as CCYYMM

$Name2 = "Mark";

$Date2 = "200803";

 

I want print them as:

 <a href=$Date1.php>$Name1 - $Date1</a> <br>
<a href=$Date2.php>$Name2 - $Date2</a> <br>

 

But I am unsure how I build the array in the first place.

 

My second question is, can I convert the date variable to the month name, ie "February 2008", "March 2008", in the link after the name variable?

 

Thanx!

 

Pete

 

Link to comment
https://forums.phpfreaks.com/topic/98757-muliti-dimensional-array-question-w-date/
Share on other sites

<?php
$Name1 = "John";
$Date1 = "200802";   // Formatted as CCYYMM
$Name2 = "Mark";
$Date2 = "200803";

$data = array(
              array ($Name1, $Date1),
              array ($Name2, $Date2),
        );

foreach ($data as $item)
{
    list($nm, $dt) = $item;
    $display = date('F Y', strtotime($dt.'01'));
    echo "<a href='$dt.php'>$nm - $display</a><br/>";
}		
?>

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.