Q:

Error: Array to string conversion at some profile pages

I'm looping trough an array when viewing the userprofile:
 <?php foreach(unserialize($contact->search_data) as $searchData): ?>
      <li><?= $searchData; ?></li>
    <?php endforeach; ?>

But at some userprofile-pages I'm getting this error: 
Array to string conversion 
This is the data from a working userprofile:
a:2:{s:8:"zip_code";s:6:"3829BE";s:8:"distance";s:2:"15";}

Its result: 3829BE 15
This is the data from an userprofile with the error:
a:3:{s:12:"Specialiteit";a:1:{i:0;s:18:"Fit worden/blijven";}s:8:"zip_code";s:6:"4731TP";s:8:"distance";s:2:"20";}

How to catch this error?
SOLUTION:
<?php if($contact->search_data): ?>
    <ul>
    <?php foreach(unserialize($contact->search_data) as $searchData): ?>
      <li><?php 
      if(is_array($searchData)){
        echo '<ul>';
        foreach($searchData as $searchDatas):
          echo '<li>';
        echo $searchDatas;
        echo '</li>';
        endforeach;
        echo'</ul>';
      }else{
      echo $searchData; } ?></li>
    <?php endforeach; ?>
    </ul>
  <?php else: ?><i>Geen</i><?php endif; ?>

A:

you cannot echo an array. Use print_r(). Then you will get to know how to access the elements present inside that.
<li><?php print_r($searchData) ?></li>

