I know that since php 5.6 you can set a constant as an array, but is it possible to build one dynamically?
This works:
const FIELDS = array("email","firstName");
But I'd like to run a query that populates the constant instead:
while($row = mysqli_fetch_assoc($results)) {
const FIELDS[] = $row['field'];
}
But that doesn't work. I also tried:
while($row = mysqli_fetch_assoc($results)) {
$array[] = $row['field'];
}
const FIELDS = $array;
But this also doesn't work. Is there a way to accomplish this? Or does the array have to be hardcoded to be set as a constant?