php - Dumping an Array -


i have basic setup wordpress advanced custom fields. have need add fields custom post , display them on post page. have code work, when got custom field has multiple checkbox selections, particular field dumps out word ‘array’, array.

how can make code below, dump labels , data regular fields fields have array in them.

$fields = get_field_objects(); if( $fields )  { echo '<div class="item-info-custom">';         echo '<dl class="item-custom">';         echo '<dt class="title"><h4>custom information</h4></dt>';             foreach( $fields $field_name => $field )                 {                     echo '<dt class="custom-label">' .    $field['label'] . ': </dt>';                     echo '<dd class="custom-data">' . $field['value'] . '</dd>';                 }          echo '</dl>'; echo '</div>'; } 

this final code got work:

<?php  $fields = get_field_objects(); if( $fields )  { echo '<div class="item-info-custom">';         echo '<dl class="item-custom">';         echo '<dt class="title"><h4>custom information</h4></dt>';             foreach( $fields $field_name => $field )                 {                         echo '<dt class="custom-label">' .         $field['label'] . ': </dt>';                     echo '<dd class="custom-data">';  if (is_array($field['value'])) { echo implode(', ', $field['value']); } else {  echo $field['value']; }  echo '</dd>';                 }          echo '</dl>'; echo '</div>'; }  ?> 

you'll need type checking. can use functions is_array() , additional logic.

for example:

echo '<dd class="custom-data">';  if (is_array($field['value'])) {   echo implode(', ', $field['value']); } else {   echo $field['value']; }  echo '</dd>'; 

Comments