我有这样的形式:
<div class="clone-wrapper" data-id="education">
<div class="row cloneable" data-id="0">
<div class="col-md-6">
<div class="form-group">
<label><?php echo System::translate("Education Institution Name"); ?></label>
<input placeholder="<?php echo System::translate("ex : University"); ?>" name="education[0][institution]" type="text" class="max_len" maxlength="100" value="">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label><?php echo System::translate("Education Degree"); ?></label>
<input placeholder="<?php echo System::translate("ex : Bachelor Degree"); ?>" name="education[0][degree]" type="text" class="max_len" maxlength="100" value="">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label><?php echo System::translate("Date of Enrollment"); ?></label>
<input placeholder="<?php echo System::translate("ex : January 2001"); ?>" name="education[0][year_begin]" type="text" class="monthyearpicker" autocomplete='off' value="">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label><?php echo System::translate("Date of Completion"); ?></label>
<input placeholder="<?php echo System::translate("ex : December 2004"); ?>" name="education[0][year_finish]" type="text" class="monthyearpicker" autocomplete='off' value="">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label><?php echo System::translate("Education Note"); ?></label>
<textarea rows="6" class="form-control" name="education[0][about]"></textarea>
</div>
</div>
</div>
</div>
<div class="white-space-20"></div>
<div class="row text-right">
<div class="col-md-12">
<div class="btn btn-default btn-sm clonable-button" data-clone="education">
<i class="fa fa-plus"></i><?php echo System::translate("Add Education"); ?></div>
</div>
</div>
如您所见,我现在像education[0][inputname]
现在那样使用名称数组,我的问题是这正在创建一个没有值的数组,因此我无法检查它们是否没有在输入中输入值。它返回:
Array
(
[0] => Array
(
[company] =>
[title] =>
[year_begin] =>
[year_finish] =>
[country] =>
[notes] =>
)
)
如何使它返回一个空数组,以便可以继续使用!empty()
?
只需过滤出空元素并检查:
if(empty(array_filter($_POST['education'][0]))) {
// array is empty
}
如果您需要检查任何空元素,则:
if(count(array_filter($_POST['education'][0])) != count($_POST['education'][0])) {
// one or more elements are empty
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句