Title: Array for checkbox
Last modified: June 22, 2018

---

# Array for checkbox

 *  Resolved [Junaid Rashid](https://wordpress.org/support/users/sjkjk53j5kl3j/)
 * (@sjkjk53j5kl3j)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/array-for-checkbox/)
 * I have made a form (selection of books), with multi selection checkbox. I have
   not added any values to them, because i am planning to show selective data in
   pdf only.
    I have gone through all the documentation, i easily used this code
   to make show list of selected items.
 *     ```
       /* Output in a list */
       if ( is_array( $form_data['field'][1] ) ) {
           echo '<ul>';
   
           foreach ( $form_data['field'][1] as $item ) {
               echo "<li>$item</li>";
           }
   
           echo '</ul>';
       }
       ```
   
 * Then i wanted to pass this data in array and show selective data using if,else
   statements. I used this code
 *     ```
       <?php 
          $book = $form_data['field'][1];
   
       ?>
       ```
   
 * Then used this code for initial statement
 *     ```
       <p>You have chosen <?php echo $book; ?> Here is the explanation!</p>
       ```
   
 * but is showing this statement
    ** “You have chosen Array Here is the explanation!”
 * From where did the array came??
    Can anyone help?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Jake Jackson](https://wordpress.org/support/users/blue-liquid-designs/)
 * (@blue-liquid-designs)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/array-for-checkbox/#post-10427140)
 * Hi Junaid,
 * Checkbox fields are stored as PHP arrays in `$form_data` because users can select
   more than once answer. That’s why the initial snippet you’ve included above loops
   through that array to output the data. If you only want a user to select one 
   answer I’d recommend a Radio or Select field instead.
 * If you’re happy allowing users to select multiple options, you can convert the
   array to a string first:
 *     ```
       <?php $books = implode( ', ', array_filter( (array) $form_data['field'][1] ) ); ?>
       <p>You have chosen <?php echo $books; ?> Here is the explanation!</p>
       ```
   
    -  This reply was modified 7 years, 11 months ago by [Jake Jackson](https://wordpress.org/support/users/blue-liquid-designs/).
      Reason: fix PHP snippet
 *  Plugin Author [Jake Jackson](https://wordpress.org/support/users/blue-liquid-designs/)
 * (@blue-liquid-designs)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/array-for-checkbox/#post-10427155)
 * Also, if you’d like to conditionally show content based on the Checkbox field
   you can do something like this:
 *     ```
       <?php if ( in_array( 'Book', (array) $form_data['field'][1] ) ): ?>
           Conditional content
       <?php endif; ?>
       ```
   
 *  Thread Starter [Junaid Rashid](https://wordpress.org/support/users/sjkjk53j5kl3j/)
 * (@sjkjk53j5kl3j)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/array-for-checkbox/#post-10431277)
 * Thanx buddy, its done !!! Thanx a lot !!
    -  This reply was modified 7 years, 11 months ago by [Junaid Rashid](https://wordpress.org/support/users/sjkjk53j5kl3j/).
    -  This reply was modified 7 years, 11 months ago by [Junaid Rashid](https://wordpress.org/support/users/sjkjk53j5kl3j/).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Array for checkbox’ is closed to new replies.

 * ![](https://ps.w.org/gravity-forms-pdf-extended/assets/icon-256x256.png?rev=3168987)
 * [Gravity PDF](https://wordpress.org/plugins/gravity-forms-pdf-extended/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gravity-forms-pdf-extended/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gravity-forms-pdf-extended/)
 * [Active Topics](https://wordpress.org/support/plugin/gravity-forms-pdf-extended/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gravity-forms-pdf-extended/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gravity-forms-pdf-extended/reviews/)

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)

 * 3 replies
 * 2 participants
 * Last reply from: [Junaid Rashid](https://wordpress.org/support/users/sjkjk53j5kl3j/)
 * Last activity: [7 years, 11 months ago](https://wordpress.org/support/topic/array-for-checkbox/#post-10431277)
 * Status: resolved