OK, this is making no sense and is the first time i have had this problem.
Please tell me i am being stupid or something.
Here is my function:
function getCountry($n, $origCode)
{
global $countryData;
if(strlen($n) > 0)
{
if(isset($countryData[$n]))
{
//$return = $countryData[$n];
var_dump($n);
return $n;
}
else
{
$n = substr($n, 0, -1);
getCountry($n, $origCode);
}
}
else
{
echo "ERROR exiting couldn't find code $origCode $count<br>";
}
}
This is the call
foreach($file as $line)
{
$split = explode(",", $line);
echo "using $split[1]<br>";
$country = getCountry(trim($split[1]), trim($split[1]));
var_dump($country);
echo "<br>";
}
File array:
$file = array("AA,93",
"BB,9370",
"CC,9378",
"DD,9377",
"EE,937",
"FF,9379",
"GG,355",
"HH,35568",
"II,35567"
);
Country data array is
array('93'=>array('id'=>2')
'355'=> array('id'=>'3)
);
The var_dumps are:
using 93
string '93' (length=2)
string '93' (length=2)
using 9370
string '93' (length=2)
null
using 9378
string '93' (length=2)
null
using 9377
string '93' (length=2)
null
using 937
string '93' (length=2)
null
using 9379
string '93' (length=2)
null
using 355
string '355' (length=3)
string '355' (length=3)
using 35568
string '355' (length=3)
null
using 35567
string '355' (length=3)
null
What i dont understand at all is why when i var_dump just before i return the value it is ok but once a var_dump out of the function i get null
This is confusing me and i have no idea.
Any ideas??
Regards
Liam
returnon your call togetCountryin theelse... it should bereturn getCountry($n, $origCode);