我有一个包含输入数组的元盒:
<input type="text" name="activite_dates[]" size="30" /><br />
<input type="text" name="activite_dates[]" size="30" /><br />
<input type="text" name="activite_dates[]" size="30" /><br />
...
我就这样保存着
update_post_meta( $post_id, "dates", $_POST[\'activite_dates\'] );
问题是,当我检索它时,我必须生成一个丑陋的函数来读取多维数组
Array
(
[0] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
)
[1] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
)
[2] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
)
()
当我保存它时,它只是添加到现有数组中
Array
(
[0] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
[4] => DATA1
[5] => DATA2
[6] => DATA3
[7] => DATA99
)
[1] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
[4] => DATA1
[5] => DATA2
[6] => DATA3
[7] => DATA99
)
[2] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
[4] => DATA1
[5] => DATA2
[6] => DATA3
[7] => DATA99
)
)
那么首先,为什么我在第一级有3个值,然后我的数组在第二级内相乘?
有关信息,请参阅我的视图代码:
$dates_gf = get_post_meta( $object->ID, \'dates\', false );
foreach ($dates_gf as $date_gf) {
if (is_array($date_gf)){
foreach ($date_gf as $arr_date_gf) {
?> <input type="text" name="activite_dates_gf[]" value="<?php echo $arr_date_gf; ?>" size="30" /><br /> <?php
}
} else {
?> <input type="text" name="activite_dates_gf[]" value="<?php echo $date_gf; ?>" size="30" /><br /> <?php
}
} ?>
非常感谢!