Jump to content

[SOLVED] Return Information from Class


papaface

Recommended Posts

Hello,

I have the following class:

<?php

class lottery
{
var $filehandlehandle;
var $data = array();
var $numbers;

	function lottery($filelocation)
		{
			$this->filehandle = file($filelocation);

			foreach($this->filehandle as $key => $value)
				{
				$this->filehandle[$key] = preg_replace('/\s\s+/', ' ', $value);
				if	($this->filehandle[$key] == " ")
					{
					unset($this->filehandle[$key]);
					}
				} 
			$output = array_slice($this->filehandle, 14);
			$count = count($output) - 26;
			$output = array_slice($output, 0,$count);


			foreach($output as $key => $value)
				{
				$value = strip_tags($value);
				$value = explode(" ",$value);
				$this->data[$key] = $value;
				} 

			foreach($this->data as $key => $value)
				{
				if	($this->data[$key][0] == "All" || $this->data[$key][0] == "")
					{
					unset($this->data[$key]);
					}
				else
					{
				//print_r($this->data[$key]);

				//echo "<br /><br />";
					}
				}

			}

		function defineNumbers($numbers)
			{
			$this->numbers = $numbers;
			}

		function getResults()
			{
				foreach	($this->data as $key => $value)
					{
					$numMatched = 0;
					$regularnumbers = array_slice($this->data[$key], 5, 7);
					foreach($regularnumbers AS $n)
						{
						if(in_array($n, $this->numbers))
							{
							$numMatched++;
							}
						}
				/*	
				$this->data[$key][0] = Draw Number
				$this->data[$key][1] = Day of the week
				$this->data[$key][2] = day of the month
				$this->data[$key][3] = month
				$this->data[$key][4] = year
				$this->data[$key][5] - $this->data[$key][10] = ball 1 - 6
				$this->data[$key][11] = bonus
				$this->data[$key][12] = jackpot
				$this->data[$key][13] = wins
				$this->data[$key][14] = machine
				$this->data[$key][15] = set
				*/
					switch	($numMatched)
						{
							case "7":
							$won = array("won lottery");
							$won[] = $this->data[$key];
							return $won;
							break;
							case "3":
							$won = array("won 10 pounds");
							$won[] = $this->data[$key];
							return $won;
							break;
						}
					}	

			}
}

?>

At the end in the getResults() method I want to return all the arrays that match 7 numbers or 3. I dont know how to do this. Can someone point me in the right direction?

Currently I only get one array returned like this:

Array ( [0] => won 10 pounds [1] => Array ( [0] => 1222 [1] => Sat [2] => 8 [3] => Sep [4] => 2007 [5] => 04 [6] => 10 [7] => 20 [8] => 24 [9] => 39 [10] => 49 [11] => (31) [12] => 2,443,024 [13] => 2 [14] => Amethyst [15] => 8 [16] => ) )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.