Solved

array within an array in PHP

Posted on 2012-04-03
2
259 Views
Last Modified: 2012-04-03
Hi: I have an array that counts the required number of columns and rows and generates a table, the code is attached. Now I have another date array which I need to insert within my <td> tag and I am not able to get it to work. The first date needs to be shown in "$firstCell" and the dates need to be populate till the "$lastCell".Can someone let me know how this can be done. Thank you.

A
existingArray.txt
arrrayToInclude.txt
0
Comment
Question by:aej1973
2 Comments
 
LVL 14

Accepted Solution

by:
Scott Madeira earned 200 total points
ID: 37804317
First of all, if $nudates is supposed to be an array then you need to do something like this to save it as an array:

// Initialize the variable
$nudates = null;

for ($count=1; $count<60; count++}
{
    // Calculate the date and save it to the array
    $date = strtotime("+$count day", $timestamp);
    $nudates[] = date("M d", $date);
}

Open in new window


In your code you will need use a counter for your array and then insert the next value each time through the inner loop.  you will need to make sure you don't try to put more than 59 dates in your table because you are only making 59 date values.


// set counter for your date array
$i = 0;
for($l=1; $l<$lines; $l++){
    $output.= "<tr>\n";
    // iterate through each column
	
    for($c=1; $c<$cols; $c++){
    	// determine this cell number
    	$cellnumber = $l*10+$c;		
    	// determine this cell color
    	if($cellnumber >= $firstCell && $cellnumber <= $lastCell)
		{
    		$color = "#99CC66";    // defined range's cell color
    	}
		else
		{
    		$color  = "white";  // default cell color
    	}
		
		    $output.= "<td style=\"background-color:$color;\" name=\"$cellnumber\">$nudates[$i]</td>\n";
                     $i++;
    }
    $output.= "</tr>\n";
}

Open in new window

0
 

Author Closing Comment

by:aej1973
ID: 37804622
Thanks a ton. Exactly what I was looking for.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question