# Return a 2 dimentional array and get values

• Nov 9, 2011, 08:05
Cyanide_Pierce
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(1, 3);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(1, 3);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
• Nov 9, 2011, 09:15
StarLion
Either global \$holis or return it.
Pass \$i as a parameter.