0

I have an array of e-mails. I'm basically trying to create new arrays from the values in this array. For example, if there is an array "[email protected]", I want to create an array [email protected] (or something like this; I understand that the @ symbol may be invalid). My head is all mixed up I think since I've been using jQuery and I can't figure out how to do this. I am familiar with reg_ex so I don't have a problem using that if that's what would work best. I'd like to name the arrays this so I can then assign certain things to them later corresponding to the e-mail address. Is this possible? Let me know if I'm way off bases here. Here's the code I have so far that's not working:

$email_array = array_unique($email_array);

//MAKE E-MAIL ARRAYS

foreach($email_array as $key => $value){
    $value = array(); //I'm aware this doesn't work, but this is the idea
}

Thanks!

2 Answers 2

1

Create a multi-dimensional array:

$new_email_array = array();

foreach ( $email_array as $email ) {
    $new_email_array[ $email ] = array();
}
Sign up to request clarification or add additional context in comments.

Comments

0

If I understand what you're trying to do, you can pass the value into the loop by reference like so

foreach($email_array as $key => &$value){
    $value = array();
}
unset($value);

That will modify the values. Also, the unset($value) at the end is to release the reference to $value. If you leave this out and reuse $value, you will modify the last item in $email_array.

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.