1

Hi i got this array from my database.

 array (size=4)
      0 => 
        array (size=1)
          0 => 
            array (size=1)
              'email_1' => string '[email protected]' (length=18)
      1 => 
        array (size=1)
          0 => 
            array (size=1)
              'email_1' => string '[email protected]' (length=18)

And i need to do get like this

array (size=4)
  0 => 
    array (size=1)
        email_1' => string '[email protected]' (length=18)
  1 => 
    array (size=1)
        'email_1' => string '[email protected]' (length=18)

I tried with array_merge and all. But no idea how to archive this?

0

3 Answers 3

1

Do it like below:-

$final_array = array();

foreach($original_array as $key=>$val){
 $final_array[$key][] = $val[0]['email_1'];
}
print_r($final_array);

Output:-https://eval.in/848213

Sign up to request clarification or add additional context in comments.

Comments

1

In php it is possible to do like this

  foreach ($yourArray as $arr){
      $result[] =  $arr[0];
   }

You can get also your desired output like this:

 $result = array_map('array_collapse',$yourArray);

Comments

0

For this just assign like this to its first element.

foreach($yourArray as $array){
  $array = $array[0];
}

1 Comment

This wouldn't work. it would only allow access to the first email address.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.