本 PHP Solutions, 2nd Edition で次のコードに出くわしました
<?php
foreach ($_POST as $key => $value) {
// assign to temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
// if empty and required, add to $missing array
if (empty($temp) && in_array($key, $required)) {
$missing[] = $key;
} if (in_array($key, $expected)) {
// otherwise, assign to a variable of the same name as $key
${$key} = $temp;
}
}
?>
私の質問は、この行に関するものです:
$temp = is_array($value) ? $value : trim($value);
$value が配列に保持されている値 (ユーザーがフォームから入力したコンテンツ) である場合、値が配列であるかどうかを判断することが重要なのはなぜですか? セキュリティのためですか?