I have a constructor that defines me 3 variables as arrays in the displayQuerys class . A function of this class fills in the array "activities" for later, in an html print this array.
The problem with which I have found is that when creating a new object, it returns the three arrays, when I only want one of them.
displayQuerys Object
(
[schedule:displayQuerys:private] => Array
(
)
[activities:displayQuerys:private] => Array
(
)
[instructors:displayQuerys:private] => Array
(
)
)
The foreach stops working because I need only one of the arrays.
<?php
$activity = new displayQuerys();
$activity->showActivities(); // Rellena el array de Activities
print_r($activity); // works fine
foreach ($activity as $value) { // here stops working
echo "I'm supossed to do stuff";
}
?>
Is there any way to create this object, specify which one to choose or at least isolate so that in this case you can catch "activities" and another time , choose instructors ?
Edit: My problem has been solved by adding a return in the method of the class displayQueries, in this way if I can apply the solution of Carlos:
if ($result->num_rows>0) {
while($row = $result->fetch_assoc()) {
$this->activities[]=$row;
}
return $this->activities;
} else {
echo "0 results";
}
$conn->close();
}