php - foreach loop in json encode array -
i sending preformatted html ajax json, json have below code,
i trying pull data array db , echoing array data, not able put foreach loop in json_encode, because seems code wrong @ foreach loop,
how can achieve that?
echo json_encode(array('returnnews' => '<div class="news-item-page"> <h3 class="text-info" style="margin-top:0">'.$latestnews->news_subject.'</h3> '.$latestnews->news_content.' </div> <div class="row"> <div class="col-md-6"> <ul class="list-inline blog-tags"> <li> <i class="fa fa-tags"></i>'. foreach($news_tag_array $tag){ <a href="javascript:;"> echo $tag </a> } </li> </ul> </div> </div>'));
$tags = ''; foreach($news_tag_array $tag){ $tags .= '<a href="javascript:;">'.$tag.' </a>'; } echo json_encode(array('returnnews' => '<div class="news-item-page"> <h3 class="text-info" style="margin-top:0">'.$latestnews->news_subject.'</h3> '.$latestnews->news_content.' </div> <div class="row"> <div class="col-md-6"> <ul class="list-inline blog-tags"> <li> <i class="fa fa-tags"></i>'.$tags.'</li> </ul> </div> </div>'));
Comments
Post a Comment