This sounds so simple but for some reason its not working on my end. I have an array which will check if values exist then will act accordingly
My array contains values and my condition is meant to check 2 conditions if value "a" is contained in the array at array index 0 and "b" doesnt exist in array then do this. if value "a" at index 0 and "b" does exist then run another block of code.
//THIS CONTAINS ALL THE FIELDS SELECTED
$report_cols = $_POST['report_cols'];
$percent_amt= explode(",",$report_cols);
$n_fields_arr = array();
$b=0;
//This checks if b exists in array
if (array_key_exists('`b`', $percent_amt))
{
$b = 1;
}
if($percent_amt[0] == '`a`' && $b == 0)
{
$report_cols = str_replace("`a`,","",$report_cols);
$report_cols = str_replace(",`a`","",$report_cols);
$report_cols = str_replace(",,",",",$report_cols);
array_push($n_fields_arr,"a");
echo "done";
}
if($percent_amt[0] == '`a`' && $b == 1)
{
$report_cols = str_replace("`a`,","",$report_cols);
$report_cols = str_replace(",`a`","",$report_cols);
$report_cols = str_replace(",,",",",$report_cols);
$report_cols = str_replace("`b`,","",$report_cols);
$report_cols = str_replace(",`b`","",$report_cols);
$report_cols = str_replace(",,",",",$report_cols);
array_push($n_fields_arr,"a","b");
echo "Done AB";
}
Error I am having is that its not recongizing the two && section and keeps running the first if statement. If there is a something am missing or a better method your help will be grately appreciated