我现在有两个数组看起来像这样的:根据数组值检查复选框?
色板:
Array
(
[0] => Array
(
[swatch_id] => 8
[swatch_file] => orange_swatch.jpg
)
[1] => Array
(
[swatch_id] => 9
[swatch_file] => pink_swatch.jpg
)
[2] => Array
(
[swatch_id] => 10
[swatch_file] => green_swtach.jpg
)
)
选择的色板:
Array
(
[0] => Array
(
[swatches_has_products_id] => 18
[swatches_swatch_id] => 8
[products_product_id] => 19
)
[1] => Array
(
[swatches_has_products_id] => 19
[swatches_swatch_id] => 10
[products_product_id] => 19
)
)
我想检查一个复选框,如果$swatch['swatch_id']
等于$selected_swatches['swatches_swatch_id']
。我用下面的代码这样做:
<?php foreach ($swatches as $k => $swatch): ?>
<li>
<img src="<?php echo base_url(); ?>media/images/swatches/<?php echo $swatch['swatch_file']; ?>" height=""/>
<input type="checkbox" name="product_has_swatch[]" value="<?php echo $swatch['swatch_id']; ?>" <?php if($swatch['swatch_id'] == $selected_swatches[$k]['swatches_swatch_id']) : ?> checked="checked" <?php endif; ?> />
</li>
<?php endforeach; ?>
不过,我得到以下错误,如果没有匹配:
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 2
Filename: products/create.php
Line Number: 137
137线是if
检查我是否有匹配;我哪里错了?