0

I have an array from a database select query that looks like this;

Array ( [0] => Array ( [0] => Array ( [users] => Array ( [email] => [email protected] ) ) [1] => Array ( [users] => Array ( [email] => [email protected] ) ) ) )

How do I just get the email addresses so that it looks like this:

[email protected], [email protected]
2
  • Show us what you tried first, and then we will help you to correct your script. Commented Oct 1, 2013 at 14:18
  • Your database can most likely do what you want; do you need to sort and implode in PHP, or would sorting/imploding in the database (and returning that to PHP) be okay for you? Commented Oct 1, 2013 at 14:35

2 Answers 2

2

I've recreated you array structure for this example. I hope this will get you started.

<?php
    $all = array(
        array(
            array('users' => array('email' => '[email protected]')),
            array('users' => array('email' => '[email protected]'))
            )
        );
    $cleanarray = array();
    foreach ($all[0] as $key => $value) {
        array_push($cleanarray, $value['users']['email']);
    }
    $comma_separated = implode(",", $cleanarray);
    echo $comma_separated;
?>
Sign up to request clarification or add additional context in comments.

Comments

0

If you're just looking for a recursive array search there is one built into PHP now.

function itemTest_func($item,$key){
     if($key == 'email') array_push($item);
}

array_walk_recursive($Multi_level_array, 'itemTest_func');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.