刪除重複值,並創建一個單一的陣列已經試過到目前爲止我如何在PHP
$result = array_map("unserialize", array_unique(array_map("serialize", $surveyData)));
我也曾嘗試使用循環自定義的方式來理清,但它是這麼多亂七八糟的。
Array
(
[0] => Array
(
[question_id] => 8
[answer] => 10 patients
[question_type] => 1
[question] => How many diabetes patients do you see per month?
[question_no] => 3
[survey_id] => 2
[name] => Health Pharmacist Digital Advantage
[description] => Free One Year Subscription to Diabetes Health Pharmacist Digital Advantage magazine
)
[1] => Array
(
[question_id] => 8
[answer] => 30 patients
[question_type] => 1
[question] => How many diabetes patients do you see per month?
[question_no] => 3
[survey_id] => 2
[name] => Health Pharmacist Digital Advantage
[description] => Free One Year Subscription to Diabetes Health Pharmacist Digital Advantage magazine
)
期望的結果:
Array
(
[0] => Array
(
[question_id] => 8
[answer] => Array(
[0] => 10 patients,
[1] => 30 patients,
)
[question_type] => 1
[question] => How many diabetes patients do you see per month?
[question_no] => 3
[survey_id] => 2
[name] => Health Pharmacist Digital Advantage
[description] => Free One Year Subscription to Diabetes Health Pharmacist Digital Advantage magazine
)
請分享你到目前爲止試過! –
如果你正在使用'fetchAll()'把它改爲'fetchAll(PDO :: FETCH_ASSOC)',它會給你1個。 – MRustamzade
我認爲這裏的question_id是一種獨特的。如果您從獲取該數據的位置更改MYSQL查詢,並且您將獲得具有不同答案的獨特數據。 – Naincy