I have a problem in my PHP code. I got an array like this as example ( this array is created dynamic with data from a database).
$db_res =array('debiteur_id'=>'1020','user_id'=>'495','b2b_or_b2c'=>'B2C');
When I show the values with
foreach ($db_res as $key => $value )
{
echo $key.' - '.$value.' , ';
}
It is displaying these values what is OK
debiteur_id - 1020 , user_id - 495 , b2b_or_b2c - B2C
Now I have a function to test if some data in the array is set or not and to return some values from this $db_res array of $_POST array
function isnull_post($naam)
{
if (isset($db_res[$naam]))
return($db_res[$naam]);
else
{
if (isset($_POST[$naam]))
return($_POST[$naam]);
else
return('');
}
}
When I use the following code to show my array
foreach ($db_res as $key => $value )
{
echo $key.' - '.$value.' , ';
$val = isnull_post($key);
echo ('isnull : '.$val.' , ');
}
This is my output
debiteur_id - 1020 , isnull : , user_id - 495 , isnull : , b2b_or_b2c - B2C , isnull :
What am I doing wrong?
$db_resis not accessible in your functionisnull_postyou need to pass it along with the key.global $db_res;as first line in your functionisnull_post$db_resvalue!? which you have written in the function!? Is it global variable!? Just try to print that value in that function so that you came to know if it will return the value or not!? What array it will print let me know.