O
O
Orange___XD2015-01-03 22:49:03
PHP
Orange___XD, 2015-01-03 22:49:03

How to fix problem with foreach loops and php array?

Hello. I have this code:

$textareaValue = '[email protected]|aaa/[email protected]|bbb/[email protected]|ggg';
$smth = explode('/n',$textareaValue);
foreach ($smth as $aa => $bb) {
list($emails, $passwords) = explode('|', $bb);
foreach ($emails as $a1 => $b1) {
    echo $b1.':';
}
foreach ($passwords as $a2 => $b2) {
     echo $b2.'<br>';
     } 
}

The code first divides the string into strings of the form "[email protected]|aaa" and adds them to the array, and then divides each string in the array into two more parts, but they are written to two different arrays. It is not at all clear what is going on with the keys in them: 0 or 1 is randomly set. Please tell me how to combine them after division into one array of the form $key => $item, where $key will be equal to "[email protected]" (Example), and $item will be equal to "test" (Example)? Or at least how to make the keys in arrays after division go from 0 to n?
There are suspicions that the problem is in list(), but I don’t know how to fix it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yanchumak, 2015-01-03
@Orange___XD

/n is a newline? if so, it's not a new line, here's the newline character \n

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question