Question : looping array makes array not empty, even though reset applied at start of loop

hello~

hope just missing something simple here
for some reason when i am looping a function, the array does not "reset/empty" even though have specified to do so at start of each loop, with both unset and array()

in example code given, the last domain in array is expecting to yield "NO MX"
eg: if only run the cut portion per comments, it does yield "NO MX" BUT when running as a whole, it seems to carry over the array from previous domain and yields "YES MX"

not sure why
thanks~
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
<?php
$array = array("google.com", "yahoo.com", "ihavenomx.com");

for($c=0; $c < 3; $c++)
{
$domain = "$array[$c]";
unset($mxrecords);
$mxrecords = array();

//start cut from here without loop from above
getmxrr($domain, $mx_host, $mx_weight);

	for($i=0; $i < count($mx_host); $i++)
	{
	$mxrecords[$mx_host[$i]] = $mx_weight[$i];
	}
		if (empty($mxrecords))
		{
		echo "NO MX<br>";
		}
			else
			{
			echo "YES MX<br>";
			}
//end cut
}
?>

Answer : looping array makes array not empty, even though reset applied at start of loop

Try this and see if it makes sense to you.  HTH, ~Ray
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
<?php // RAY_temp_sexyabs.php
error_reporting(E_ALL);

// TEST DATA FROM THE POST AT EE
$array = array("google.com", "yahoo.com", "ihavenomx.com");

// WHERE TO KEEP THE INFORMATION
$mxrecords = array();

// AN ITERATOR
foreach ($array as $domain)
{
    // MAN PAGE: http://us2.php.net/manual/en/function.getmxrr.php
    $x = getmxrr($domain, $mx_host, $mx_weight);
    
    
    // ADD THE RESULTS TO THE KEEPING ARRAY
    $mxrecords[$domain] 
    = array 
    ( 'mx_exists' => $x
    , 'mx_host'   => $mx_host
    , 'mx_seight' => $mx_weight
    )
    ;
}

// SHOW THE WORK PRODUCT
echo "<pre>" . PHP_EOL;
var_dump($mxrecords);
Random Solutions  
 
programming4us programming4us