{
"apple":[
"get",
"get me an apple"
],
"orange":[
"get me one",
"get some"
],
"banana ":[
"cut them all",
"get them"
],
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得格式?我使用print_r($ sql)打印短语和动作列时的SQL输出; 是
Array ( [phrases] => get [actions] => apple )
Array ( [phrases] => get me an apple [actions] => apple )
Array ( [phrases] => Get me one [actions] => orange )
Array ( [phrases] => Get some [actions] => orange )
Array ( [phrases] => cut them all [actions] => Banana )
Array ( [phrases] => get them [actions] => Banana )
请帮忙.谢谢...
试一试简单:
$tempArray = array();
while($rec = mysql_fetch_assoc($sql)){
$tempArray[$rec['actions']][] = $rec['phrases'];
}
echo json_encode($tempArray);
Run Code Online (Sandbox Code Playgroud)