M
M
Mr_Fads2021-09-02 23:36:03
PHP
Mr_Fads, 2021-09-02 23:36:03

How to get the same value from the input "xfield[2][h2]"?

Need help with array processing.

There are several inputs:

<input id="xf_txt1" name="xfield[1]" value="Заголовок1" class="head_txt"/>
<input id="xf_txt2" name="xfield[2][h2]" value="Заголовок2" class="head_txt"/>
<input id="xf_txt3" name="xfield[3]" value="Заголовок3" class="head_txt"/>


php itself:
foreach( $_POST['xfield'] as $item ) {
 $items[] = $item;
}

$add = implode( $items,'<br>' );


Outputs:
Заголовок1
Array
Заголовок3


How to get the same value from the input "xfield[2][h2]"?

To make it happen:
Заголовок1
Заголовок2
Заголовок3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2021-09-03
@Mr_Fads

options:
1. remove [h2] from the input
2. learn how to work with arrays in general and is_array in particular
3. forget to bypass the array, work directly with indices.
4. think of other ways

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question