K
K
Kirill Gorelov2016-04-14 21:05:29
PHP
Kirill Gorelov, 2016-04-14 21:05:29

Why is the array not formed in foreach?

Hello.
Why is the array not formed?

$outbad = array();
$outgood = array();
foreach((array)$emails as $key=>$e){
if (да){
$outgood[] .= $emailadress['dfgh'] . " хороший адрес"; // и такой вариант
} else{
$outbad[] .= array($emailadress . " плохой адрес"); // и такой вариант
}
echo $outgood;
echo $outbad;

The cycle sorts out something of its own, this is not the point. The bottom line is that the array is not formed. Failure in different ways.
And tried another option.
$outbad[] = array($emailadress . " плохой адрес");
$outgood[] = $emailadress['dfgh'] . " хороший адрес";

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DTX, 2016-04-14
@Kirill-Gorelov

And emails - what is it?

$ems = array('abc', 'def');
$outbad = array();
$outgood = array();

foreach ($ems as $val) {
  if (true) {
    $outgood[] = $val.' - OK';    
  } else {
    $outbad[] = $val.' - FAIL';   
  }
}
echo $outgood;
echo $outbad;

V
Vladislav Shkaev, 2016-04-14
@proxid

from the ceiling because you take variables) you are in a cycle, use either a key or a variable that distributes $key $e. push or so $outgood[] = $e or array_push($outgood, $e);

foreach($emails as $key=>$e){
if (да) {
    $outgood[] = $e . " хороший адрес";
} else {
    $outbad[] = [$key . " плохой адрес"]; 
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question