II'm using an API and was wondering why I am having trouble getting an array to cross into a function. The following works fine but how can I make it work for an array.
public function __construct()
{
parent::__construct(); // Init parent constructor
$this->dbConnect();
$this->test();
}
public function test()
{
$this->category = "bracelets";
}
private function piece()
{
// Pass an array into this function here and then use depending on array key
$cat = $this->category;
}
So instead of a constant $this->category="bracelets. I would like this to be an array. e.g.
public function test()
{
$array = [
"foo" => "bar",
"bar" => "foo",
];
$this->category = $array;
}
Ok, this has been resolved. It was due to a minor error elsewhere. For a moment I believed there was an issue with arrays in a restful API.
I hope this is useful to any others who wish to pass one function results to another in an api class.