Reputation: 2121
I'm looking at a function in Keyring that has a bunch of PHP tags inside of it but no obvious return statement or even an echo to wrap everything. Could someone tell me what this is called and how to think about what's happening here?
static function token_select_box( $tokens, $name, $create = false ) {
?><select name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $name ); ?>">
<?php if ( $create ) : ?>
<option value="new"><?php _e( 'Create a new connection…', 'keyring' ); ?></option>
<?php endif; ?>
<?php foreach ( (array) $tokens as $token ) : ?>
<option value="<?php echo $token->get_uniq_id(); ?>"><?php echo $token->get_display(); ?></option>
<?php endforeach; ?>
</select><?php
}
Upvotes: 0
Views: 70
Reputation: 740
This function is building a select box.
The <select>
tag in HTML is used to create a dropdown selection box. This PHP code is essentially creating the individual items within that select box... so for each $token
a new <option>
is created within the select box.
As, @Quentin pointed out - anything outside of <?php ... ?>
will be treated as HTML and will output similar to echo
or print
.
Upvotes: 1
Reputation: 943979
Putting content outside of <?php ... ?>
causes it to be output just like an echo
or print
.
Upvotes: 2