Solved

# array within an array in PHP

Posted on 2012-04-03
Medium Priority
263 Views
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
Question by:aej1973
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 14

Accepted Solution

Scott Madeira earned 800 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);
}

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";
}
0

Author Closing Comment

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

## Featured Post

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
###### Suggested Courses
Course of the Month14 days, 5 hours left to enroll