# Thread: Return a 2 dimentional array and get values

1. ## Return a 2 dimentional array and get values

Im using the following code quite often and wish to take some of the code and put it into a function and call the funtion and still output the array data.
This is what i have:

PHP Code:
for(\$i 1\$i <= \$years\$i++)
{
\$month rand(13);
if(
\$month == 1)
{
\$holis[\$i][0] = "April";
\$holis[\$i][1] = \$april;
}
elseif(
\$month == 2)
{
\$holis[\$i][0] = "May";
\$holis[\$i][1] = \$may;
}
elseif(
\$month == 3)
{
\$holis[\$i][0] = "August";
\$holis[\$i][1] = \$august;
}
\$total \$total \$holis[\$i][1];
echo
"Year \$i holidays are in {\$holis[\$i][0]} and you get {\$holis[\$i][1]} days worth of holidays.<br />\n\t";

I wish to make it something like this, use a functon to set and check the month before outputing the data

PHP Code:
function setMonth()
{
\$month rand(13);
if(
\$month == 1)
{
\$holis[\$i][0] = "April";
\$holis[\$i][1] = \$april;
}
elseif(
\$month == 2)
{
\$holis[\$i][0] = "May";
\$holis[\$i][1] = \$may;
}
elseif(
\$month == 3)
{
\$holis[\$i][0] = "August";
\$holis[\$i][1] = \$august;
}
}

if(
\$option == 1)
{
echo
"<p>\n\t";
for(
\$i 1\$i <= \$years\$i++)
{
setMonth();
\$total \$total \$holis[\$i][1];
echo
"Year \$i holidays are in {\$holis[\$i][0]} and you get {\$holis[\$i][1]} days worth of holidays.<br />\n\t";
}

Ive tried different things to get setMonth() to output the data

2. Either global \$holis or return it.
Pass \$i as a parameter.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•