I'm trying to use array_push to create an array that looks like this:
array(
"SaleTypeCat1" => array("Type1", Type2","Type3"),
"SaleTypeCat2" => array("Type3")
)
My code fails on this line:
$this->valid_sale_types_categories[$row->sale_category] = array();
with:
PHP Parse error: syntax error, unexpected T_VARIABLE
This is my code - From what I have seen and read, I have followed the instructions to initialise my array however, the error suggests I'm not doing it correctly?
class SaleTypes {
private $valid_sale_types_categories;
function getSaleTypes($customer_id) {
...
while ($row = $result->fetch_object()) {
//Need to initialise the array before trying to push a value to it.
if (!isset($this->valid_sale_types_categories[$row->sale_category])
$this->valid_sale_types_categories[$row->sale_category] = array();
array_push($this->valid_sale_types_categories[$row->sale_category], $row->sale_type);
}
...
}
}
If I try to just push the array before initializing I get a different error:
PHP Warning: array_push() [<a href='function.array-push'>function.array-push</a>]: First argument should be an array