papaface Posted September 13, 2007 Share Posted September 13, 2007 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 https://forums.phpfreaks.com/topic/69209-solved-return-information-from-class/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.