Here is my code:
$convertTitle = $this->art->catList(); // gets an array which has other arrays as its values
foreach($convertTitle as $cT){ // cycle through the smaller arrays
if(in_array($cat, $cT)){ // if "xx" is found in a smaller array
$data['title'] = $cT['full']; // set the $title to the full form corresponding to the abbreviated xx ($cat)
}
if(!in_array($cat, $cT)){
$data['title'] = "Sorry, an error occurred."; // if it's not found, choose an alternate title
$data['error'] = 1; // throw the error
}
}
In order to debug, I've been printing in_array($cat, $cT) and when I expect it to, it outputs 1. When I expect it to, it outputs 0 as well. So it seems like it's working.I can even print($data['title']); and the correct title shows up! But regardless of whether in_array() is outputting 1 or 0, my second if statement always overrides the first and I $error always comes out 1. What gives?
Some solutions I've tried:
if(!in_array($cat, $cT)...
if(in_array($cat, $cT) == false/0/null)...
else...
I really have no idea why it's not outputting the proper title when the title is located in the variable when I want it to be!
EDIT:
Here is print_r($convertTitle);
Array ( [0] => Array ( [handle] => dr [full] => Drawings ) [1] => Array ( [handle] => f [full] => Films & Stills ) [2] => Array ( [handle] => pa [full] => Paintings ) [3] => Array ( [handle] => ph [full] => Photography ) [4] => Array ( [handle] => po [full] => Portraits ) )
elsestatement instead of anotherifbecause your code paths should be mutually exclusive. Also, can you include some examples of$catand$cT?print_r($convertTitle);. Are you aware you can useif(...){...}else{...}?