How do I compose a function with a section that is able to be defined when the function is called?
<?php
class MyClass {
function doSomething() {
$conn = $this->connectToDatabase("database");
$rows = $conn->query($query);
if ($rows->num_rows > 0) {
while($row = $rows->fetch_assoc()) {
$col_value = $row['name'];
function defineMe() {
//i need to be defined when called
}
}
} else {
echo "0 results";
}
$conn->close();
}
}
?>
That way, say I wanted to pull data from a database, I can change defineMe() to match the layout of the info that its spitting out. How can I override this function and still access the data from the doSomething() function?
Like
$myClass = new MyClass;
$myClass->doSomething(){
function defineMe() {
echo $col_value;
}
};