数据库:
ID str域
1 x.com
2 y.com
3 z.com
$domainSettings = array();
$db_domainList = DB::get("SELECT strDomain FROM domains ORDER BY id ASC;");
foreach($db_domainList as $row) {
$domainSettings = array($row->strDomain);
}
$result = array('allowedDomains' => $domainSettings);
echo json_encode($result, JSON_FORCE_OBJECT);
当前输出:{"allowedDomains":{"0":"x.com"}}
我需要类似于这样的输出:{"allowedDomains":"x.com","y.com","z.com"}
输出echo json_encode($db_domainList);:
[{"strDomain":"x.com"},{"strDomain":"z.com"},{"strDomain":"y.com"}]
慕田峪9158850
慕姐4208626