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();
You can also use defined values. other wise good to pass in constructor
here is running snippet: https://ideone.com/miOQJB