I have 2 functions (Located in same file)
f1 = getBlogCommentList
f2 = getBlogReplyList
I want function f1 to call f2 $this->getBlogReplyList($post_id,$comment['id']);, f2 function collect data from sql based on f1 sent parameters and returns array with data return $blog_replies;. And returned data I want to use in f1, but can't understand how to reach this returned data. foreach ($blog_replies as $reply) { //Do stuff with returned data }
Notice: Undefined variable: blog_replies in D:\xampp\htdocs\models\BlogModel.php on line 146
Warning: Invalid argument supplied for foreach() in D:\xampp\htdocs\models\BlogModel.php on line 146
In Line 146 I have foreach($blog_replies as $replies)
f1 function (getBlogCommentList)
public function getBlogCommentList($post_id){
try{
$sortby = "bla bla bla";
$stmt = $this->conn->prepare("$sortby");
$stmt->execute();
$result = $stmt->fetchAll();
$blog_comments = array();
foreach($result as $comment){
$blog_comments[] = $comment;
$this->getBlogReplyList($post_id,$comment['id']);
}
foreach ($blog_replies as $reply) {
//Do stuff with returned data
}
return $blog_comments;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
f2 function (getBlogReplyLyst)
public function getBlogReplyList($post_id,$comment_id){
try{
$sortby = "bla bla bla";
$stmt = $this->conn->prepare("$sortby");
$stmt->execute();
$result = $stmt->fetchAll();
$blog_replies = array();
foreach($result as $post){
$blog_replies[] = $post;
}
return $blog_replies;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}