我知道Laravel webservice。其实我的结果是
{"key_skills_details":[{"id":31,"key_skills":"anroid,php,html"}]}
但我想要
{"key_skills_details":[{"id":31,"key_skills":"anroid"}],[{"id":31,"key_skills":"php"}],[{"id":31,"key_skills":"html"}]}
我的代码如下。
public function getKeyskillshow(){
$user_id=$_REQUEST['user_id'];
$profiles="SELECT `id` FROM `abserve_keyskill` where `user_id`=".$user_id;
$details=\DB::SELECT($profiles);
$reason=\DB::SELECT("SELECT `key_skills` FROM `abserve_keyskill` where `user_id`=".$user_id);
$var=explode(',',$reason);
$response['key_skills_details']=$details;
echo json_encode($response);exit;
}
答案 0 :(得分:0)
尝试这样做,希望这可以帮助你
public function getKeyskillshow(){
$user_id=$_REQUEST['user_id'];
$profiles="SELECT `id` FROM `abserve_keyskill` where `user_id`=".$user_id;
$details=\DB::SELECT($profiles);
$reason=\DB::SELECT("SELECT `key_skills` FROM `abserve_keyskill` where `user_id`=".$user_id);
$array_of_reasons = explode(',', $reason->key_skills);
$array_details = new array();
for($i=0; $i<count($array_of_reasons); $i++)
{
$array_details[$i] = array('id' => $user_id, 'key_skills' => $array_of_reasons[$i]);
}
$response['key_skills_details']=$array_details;
echo json_encode($response);exit;
}