L
L
ligisayan2018-12-11 14:08:39
PHP
ligisayan, 2018-12-11 14:08:39

Why am I getting an error when trying to get the value of a foreach index?

Hello! There is a foreach loop on the wordpress site that displays a list<input type="radio">

foreach ( $args['options'] as $option_key => $option_text ) {
        $field .= '<input type="radio"' . checked( $value, esc_attr( $option_text ), false ) . ' name="' . esc_attr( $key ) . '" value="' . esc_attr( $option_text ) . '" /><label>' . esc_html( $option_text ) . '</label>';
      }

I want to get for each id with ordinal values ​​so that they can be accessed through the label
. Why do I get an error when I try to write like this? Doesn't $option_key store a serial number?
foreach ( $args['options'] as $option_key => $option_text ) {
$field .= '<input type="radio" id=""'. echo $option_key . '"' . checked( $value, esc_attr( $option_text ), false ) . ' name="' . esc_attr( $key ) . '" value="' . esc_attr( $option_text ) . '" /><label>' . esc_html( $option_text ) . '</label>';
}

Answer the question

In order to leave comments, you need to log in

5 answer(s)
U
ummahusla, 2016-01-26
@Antonoff

freelansim.ru

Z
Zhainar, 2016-01-26
@zhainar

PHP GD2 library:
$img = imagecreatefrompng('path to image'); // open a png image, other formats are
also possible imagestring( ); // look at parameters at php.net/manual/en/book.image.php
imagepng($img, 'image name');
imagedestroy($img);

D
Dmitry Gavrilenko, 2016-01-26
@Maddox

If PHP
C#

U
Umid, 2016-01-26
@DarCKoder

If on js:
first find out the link path itself elem.getAttribute("href");
then you change this value using regular expressions and
elem.setAttribute(name, value) - sets the attribute

I
Ilya, 2018-12-11
@jasper-blondin

'<input type="radio" id=""'
In this piece of code, you open a quote for the value of the id attribute, and immediately close it.
Also, if you have a numbered array (not associative), use a for loop rather than a foreach.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question