【发布时间】:2019-03-07 12:50:45
【问题描述】:
我被困在这一点上,我希望:
对于每个不包含“+price”的名称,将值回显到输入 class="optionname" 对于每个包含“+price”的名称,将值回显到未输入的 class="optionprix"
我的 php 和 html :
foreach($fields as $field):
<input type="text" class="optionname" name="<?php echo $field['name']; ?>" value="<?php echo $field['value']; ?>"/>
Prix : <input type="text" class="optionprix" name="<?php echo $field['name'].'+price'; ?>" value="<?php echo $optionprix; ?>"
endforeach;
我的记录 $fields 是 JSON 格式 =>
array(8) {
[0] => array(2) {
["name"] => string(26) "checkboxes-label---3499163"
["value"] => string(7) "Options"
}
[1] => array(2) {
["name"] => string(25) "single-checkbox---3499163"
["value"] => string(34) "Aide à l installation du parcours"
}
[2] => array(2) {
["name"] => string(31) "single-checkbox---3499163+price"
["value"] => string(3) "500"
}
[3] => array(2) {
["name"] => string(25) "single-checkbox---3499163"
["value"] => string(27) "Location du système vidéo"
}
[4] => array(2) {
["name"] => string(31) "single-checkbox---3499163+price"
["value"] => string(2) "10"
}
[5] => array(2) {
["name"] => string(25) "single-checkbox---3499163"
["value"] => string(4) "test"
}
[6] => array(2) {
["name"] => string(31) "single-checkbox---3499163+price"
["value"] => string(2) "13"
}
[7] => array(2) {
["name"] => string(18) "required---3499163"
["value"] => bool(false)
}
}
这样当我转储 echo var_dump($field) =>
array(2) {
["name"] => string(25) "single-checkbox---3499163"
["value"] => string(34) "Aide à l installation du parcours"
}
array(2) {
["name"] => string(31) "single-checkbox---3499163+price"
["value"] => string(3) "500"
}
我不确定完成它的最佳方法,我用 count、in_array 和 explode 方法搜索但没有成功
【问题讨论】:
标签: php conditional-statements