如何在php中获取数据结果数组

I have data and stored in database, data return with result_array(), when data set to var_dump(), result like this:

array(6) {
    [0] => array(4) {
        ["id_termmeta"] => string(1)"1" 
        ["id_term"] => string(1)"1" 
        ["meta_key"] => string(9)"telephone" 
        ["meta_value"] => string(17)"(021) 456 789 xxx"
    }
    [1] => array(4) {
        ["id_termmeta"] => string(1)"2" 
        ["id_term"] => string(1)"1" 
        ["meta_key"] => string(11)"handphone_1" 
        ["meta_value"] => string(12)"08567890xxx"
    }
    [2] => array(4) {
        ["id_termmeta"] => string(1)"3" 
        ["id_term"] => string(1)"1" 
        ["meta_key"] => string(11)"handphone_2" 
        ["meta_value"] => string(7)"087654321xxx"
    }
    [3] => array(4) {
        ["id_termmeta"] => string(1)"4" 
        ["id_term"] => string(1)"1" 
        ["meta_key"] => string(11)"handphone_3" 
        ["meta_value"] => string(8)"081234567xxx"
    }
    [4] => array(4) {
        ["id_termmeta"] => string(1)"5" 
        ["id_term"] => string(1)"1" 
        ["meta_key"] => string(6)"alamat" 
        ["meta_value"] => string(16)"Jl. Jalan menuju sorga"
    }
    [5] => array(4) {
        ["id_termmeta"] => string(1)"6" 
        ["id_term"] => string(1)"1" 
        ["meta_key"] => string(5)"email" 
        ["meta_value"] => string(20)"blabla@gmail.com"
    }
}

I want to get data meta_value in array[0], meta_value in array[1], meta_value in array[2], etc..

How to make like this:

<ul class="list-contact">
   <li><a href=""><div class="list-style"><img src="tlpn.png"></div>(021) 456 789 xxx</a></li>
   <li><a href=""><div class="list-style"><img src="phone.png"></div> <p>08567890xxx<br>087654321xxx<br>081234567xxx</p></a><a href=""></a></li>
   <li><a href=""></a><a href=""><div class="list-style"><img src="marking.png"></div>
                            <p>Jl. Jalan menuju sorga</p>
                            </a></li>
   <li><a href=""><div class="list-style"><img src="msg.png"></div>blabla@gmail.com                             </a></li>
</ul>

and the result like this:

Sample output

Try this code, its worked, thanks @mohade

<ul class="list-contact">
   <li><a href=""><div class="list-style"><img src="tlpn.png"></div><?php echo $contact[0]['meta_value']; ?></a></li>
   <li><a href=""><div class="list-style"><img src="phone.png"></div> <p><?php echo $contact[1]['meta_value']; ?><br><?php echo $contact[2]['meta_value']; ?><br><?php echo $contact[3]['meta_value']; ?></p></a><a href=""></a></li>
   <li><a href=""></a><a href=""><div class="list-style"><img src="marking.png"></div><p><?php echo $contact[4]['meta_value']; ?></p>
                            </a></li>
   <li><a href=""><div class="list-style"><img src="msg.png"></div><?php echo $contact[5]['meta_value']; ?></a></li>
</ul>

you can use the foreach

// example like this
foreach(data <- datalist){
  echo data.telephone["meta_value"];
}

I am assuming that you have the given array of data available in your controller. Let's assume the name this array is$results.

First

Pass $results array to the view which you need to display this results.If your view is results.php then your code would be like

public function viewResults(){
//Your controller logic
$data = array('results' => $results);
$this->load->view('results',$data);
}

Second

Now your results array is available in your view and you can use it to get the needed result

The code below is the easiest you can do, but if it is to work properly you should only use $result with given format, for example if your array lacks "handphone_1" all the following values will be shown in wrong places.

    <ul class="list-contact">
      <li>
        <a href=""><div class="list-style"><img src="tlpn.png"></div><?php echo $results['0']['meta_value'] ?></a>
      </li>
      <li><a href=""><div class="list-style"><img src="phone.png"></div> <p><?php echo $results['1']['meta_value'] ?><br><?php echo $results['2']['meta_value'] ?><br><?php echo $results['3']['meta_value'] ?></p></a><a href=""></a>
      </li>
      <li>
        <a href=""></a><a href=""><div class="list-style"><img src="marking.png"></div><p><?php echo $results['4']['meta_value'] ?></p></a>
      </li>
      <li><a href=""><div class="list-style"><img src="msg.png"></div><?php echo $results['5']['meta_value'] ?></a>
      </li>
    </ul>

To eliminate the problem discussed you can use loop with conditional statements

<?php
$count=0; 
foreach($results as $result){ ?>
  <ul class="list-contact">
      <?php if($result['meta_key']=='telephone'){ ?>
          <li>
            <a href=""><div class="list-style"><img src="tlpn.png"></div><?php echo $result['meta_value'] ?></a>
          </li>
      <?php } ?>
      <?php if( strpos($result['meta_key'], 'handphone') !== false ){ 
          if($count==0 ) { ?>

          <li>
            <a href="">
              <div class="list-style"><img src="phone.png"></div>
          <?php $count++; } ?>
              <?php if($result['meta_key']=='handphone_1'){
                  echo $result['meta_value'].'</br>';}
              ?> 
              <?php if($result['meta_key']=='handphone_2'){
                  echo $result['meta_value'].'</br>';}
              ?>
              <?php if($result['meta_key']=='handphone_3'){
                  echo $result['meta_value'];}
              ?> 
            </a>
          </li>
      <?php } ?>
      <?php if($result['meta_key']=='alamat'){ ?>
          <li>
            <a href=""><div class="list-style"><img src="marking.png"></div><?php echo $result['meta_value'] ?></a>
          </li>
      <?php } ?>
      <?php if($result['meta_key']=='email'){ ?>
          <li>
            <a href=""><div class="list-style"><img src="msg.png"></div><?php echo $result['meta_value'] ?></a>
          </li>
      <?php } ?>
  </ul>
<?php } ?>