1

I have a foreach loop like this.

if ( is_object($res_two)) {
  if($res_two->num_rows() == 0) { 
    echo "No Records Found";}
  else if( $res_two->num_rows() > 0) {
    foreach ($res_two->result() as $row ) {
      echo $row->js_id."\t". $row->designation."\t".$row->full_name."\t".$row->location."\t".$row->graduated_in."\t";     
      $mail2 =  $row->email;      
      echo $mail2 ;

      ?>  <a href="<?php echo base_url("uploads/".$row->resume."")?>">Download Resume</a> <br/><br/>  <?php
    }
  }
}
?>

Now I want to extract $mail2 details. However echoing $mail2 out of the code giving only one value instead of an array(if foreach loop iterates, it should have multiple values?).

How to get the multiple values of $mail2 outside the code?

2
  • Just put them to array $mails[] = $row->email Commented Nov 26, 2013 at 12:37
  • 1
    Try this. Insted of: $mail2 = $row->email; use: $mail2[] = $row->email;. Now email2 is array and you can get all emails outside of foreach loop Commented Nov 26, 2013 at 12:38

1 Answer 1

1
<?php
if (is_object($res_two)) {
    if ($res_two->num_rows() == 0) {
        echo "No Records Found";
    } else if ($res_two->num_rows() > 0) {
        foreach ($res_two->result() as $row) {
            echo $row->js_id . "\t" . $row->designation . "\t" . $row->full_name . "\t" . $row->location . "\t" . $row->graduated_in . "\t";
            $mail2[] = $row->email;

            ?>  <a href="<?php echo base_url("uploads/" . $row->resume . "") ?>">Download Resume</a> <br/><br/>  <?php
        }
    }
}
print_r($mail2);
?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.