我想通過傳遞到function.here取代「created_at」替換值是我的功能如何在JSON數組用PHP
public function getfeeds($showvalue){
$stmt = $this->con->prepare("SELECT id,image,title,status,profilepic,created_at,url FROM news ORDER BY id DESC ");
$stmt->bind_param("s",$showvalue);
$stmt->execute();
$result = $stmt->get_result();
$nrow = array();
while ($r = $result->fetch_assoc()) {
$nrow[] = $r;
}
$frow['news'] = $nrow;
$json = str_replace("\\/", "/",json_encode($frow));
return $json;
}
我想傳遞給一個函數來代替在創造價值converttime($time)
我的轉換時間函數
function converttime($time, $full = false) {
$now = new DateTime;
$ago = new DateTime($time);
$diff = $now->diff($ago);
$diff->w = floor($diff->d/7);
$diff->d -= $diff->w * 7;
$string = array(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
} else {
unset($string[$k]);
}
}
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}
請幫助我,我怎樣才能將它轉換
所以你有一個功能,你知道你想要傳遞的價值......那麼問題究竟是什麼?調用函數並將所需的值傳遞給它。與此無關,您試圖將值綁定到您的語句,但您的查詢中沒有任何參數。這將是一個問題。 –
我想只提取created_在查詢然後傳遞給一個轉換函數,獲取創建的新值,並將其傳遞給json編碼 –