php - foreach echo into 2 different input from json
435
I'm stuck at this point, what I wish :
My php and html :
foreach($fields as $field):
<input type="text" name="<?php echo $field['name']; ?>" value="<?php echo $field['value']; ?>"/>
Prix : <input type="text" name="<?php echo $field['name'].'+price'; ?>" value="<?php echo $optionprix; ?>"
endforeach;
My records, $fields, are in JSON format =>
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)
}
}
By this way when I dump 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"
}
I'm not sure the best way to complete it, I search with count, in_array and explode methodes but without success
Answer
Solution:
Most accurately without regex, you only need to check the last 6 characters for a match in your condition block.
Answer
Solution:
This only checks if name is ending with 'price'
Answer
Solution:
You can do this quite simply with the use of
strpos()
as follows