我真的被这个难住了。我有这个数组变量$banner_image_description
。当我打印它时,我得到Array ( ['title'] => dafha ['price'] => adhfadhf )
.
现在,我要做的是检查'title'处值的长度并确保它大于2。所以当我运行时:
if (isset($this->request->post['banner_image']))
{
foreach ($this->request->post['banner_image'] as $banner_image_id => $banner_image)
{
foreach ($banner_image['banner_image_description'] as $language_id => $banner_image_description)
{
print_r($banner_image_description);
echo('<br/>');
if ((utf8_strlen($banner_image_description['title']) < 2) || (utf8_strlen($banner_image_description['title']) > 64))
{
$this->error['banner_image'][$banner_image_id][$language_id] = $this->language->get('error_title');
}
}
}
}
我明白Notice: Undefined index: title
了,我不知道为什么。我认为这是获取“标题”值的正确方法,我知道索引就在那里,价值就在那里。
我很确定该数组是通过 POSTing 表单值填充的:
if (isset($this->request->post['banner_image']))
{
$banner_images = $this->request->post['banner_image'];
}
以下是表单值的样子:
<input type="text"
name="banner_image[<?php echo $image_row; ?>][banner_image_description][<?php echo $language['language_id']; ?>]['title']"
value="<?php echo isset(
$banner_image['banner_image_description'][$language['language_id']]['title']) ?
$banner_image['banner_image_description'][$language['language_id']]['title'] : ''; ?>" />
<img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />