Trying to figure out how to work with array elements with a public function inside a PHP class. Have reviewed already similar questions, but without being able to resolve the issue. Below is what I have so far.
class myClass
{
public $inputNumber = 27;
public $inputArray = array(1, 2, 4);
public $outputArray = array($inputArray[0]*$inputNumber, $inputArray[1]*$inputNumber, $inputArray[2]*$inputNumber);
public function printOutput()
{
return "1st value is " . $this->outputArray[0] . "<br>";
return "2nd value is " . $this->outputArray[1] . "<br>";
return "3rd value is " . $this->outputArray[2] . "<br>";
}
}
$obj = new myClass;
echo $obj->printOutput();
returnonce within a function, so that's not going to work. If you will need to return$this->outputArray, then access the values in the calling element (or simplyechoorprintinstead ofreturn, if this suits)