書きたいのは、データベースのジェイソン文字列に格納される配列である文字列です。私のコードはチェックボックスを繰り返しますが、$input名が"interests"であるかどうかをテストできるようにしたいです
<input type="checkbox" name="interests[]" value="dvd" />` <-- checkbox lists
私が得ることができない他のことは、例えば「dvd」、「computers」のように各$valueの周りに引用符を置くことです
$interests = '[';
$count = 1;
$counter = count($_POST["interests"]);
foreach($_POST as $checkbox => $input) {
if(is_array($input)) {
// test here is input is "interests"
foreach($input as $index => $value) {
$interests .= /*quote here*/ $value /*quote here*/ .= ($count < $counter) ? ',' : '';
$count += 1;
}
}
}
$interests .= ']';
echo $interests;
興味は["dvd"、 "computers"、 "hard drive"]を書き出すことを想定していますが、それは[dvd、computers、harddrives]だけを書き出すだけです。