are you really meaning to search for the iterating number
$i ? your code is a little confusing to me. i don't think you have to keep re-declaring global vars inside your for loop.
since i don't understand exactly what your code does, i'll suggest looking at this example from php.net
PHP Code:
<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // $key = 2;
echo "green key is: " . $key . "<br>";
$key = array_search('red', $array); // $key = 1;
echo "red key is: " . $key . "<br>";
?>
try running that to make sure the keys print as you expect.
another thing you might want to try if you haven't already, is dump your array to screen to make sure it contains what you think it contains.
PHP Code:
<?
echo "<pre>";
print_r($modulead);
echo "</pre>";
?>