pablo79py
pablo79py

Reputation: 5

How to print one or more elements of the array?

I use radio buttons to choose one or more elements, but I don't know how I can make it print the selected elements.

$wyz_cmb_businesses->add_field(
array(
    'name' => esc_html__( 'delivery', 'wyzi-business-finder' ),
    'id' => $prefix . 'business_delivery',
    'type' => 'multicheck',
    'default_cb' => 'motorcycle',
    'options' => array( 'motorcycle' => esc_html__( 'motorcycle', 'wyzi-business-finder' ), 'Car' => esc_html__( 'Car', 'wyzi-business-finder' ), 'other' => esc_html__( 'other', 'wyzi-business-finder' ) ),
) );

Here you should print one or more array elements

<?php if ( '' !== $business_data['delivery'] ) {?>
    <div class="post-like">
        <a target="_blank" class="link" href="<?php echo esc_url( $business_data['delivery'] );?>">
            <i class="fa fa-globe" aria-hidden="true"></i> 
            <?php echo esc_html( $business_data['delivery'] );?>
        </a>
    </div>
<?php }?>

enter image description here

Upvotes: 0

Views: 55

Answers (1)

dmuensterer
dmuensterer

Reputation: 1885

You need to iterate the array and print the current element each iteration.

This works with numeric arrays as well as with associative arrays (which is what you're using) because all PHP arrays are internally implemented as hashmaps.

$someArray = array('1','2','3','4','5','6','7');
foreach($someArray as $value){ 
    echo $value . "<br />\n";
}

Upvotes: 1

Related Questions