I’m a noob so please be patient
I have to test an array, so that I check if it exists and to see if the numbers in it are ok.
In every case a message must be put out…for example…if the array is full and the numbers are ok I should get a message like (Array is full, Num are ok). But I use If after If and I get into trouble because…..well..take a look for yourself.
public static function getTest($ids){
$input_result = array();
foreach ($ids as $id) {
$input_result['result']['Id '.$id] = $id;
}
if((!empty($ids))){
//echo "You have inputted some data in the Api_Books_Book::getTest<br/>";
$input_success = "Successful!";
$input_message = "Array OK";
}
else
{
//echo "There is no data<br/>";
$input_success = "Not Successful";
$input_message = "Have inputed anything in the array?";
}
if(okNum($ids)) {
//echo "You have inputted some data in the Api_Books_Book::getTest<br/>";
$input_success = "Successful!";
$input_message = "numbers OK";
}
else {
//echo "There is no data<br/>";
$input_success = "Not Successful";
$input_message = "numbers not OK";
}
$result=array('status'=>$input_success,'message'=>$input_message,'result'=> $input_result);
rdie($result);
return $result;
}
This looks like your problem (although you haven’t actually told us what issue you are getting).
The above isn’t an else so the “Not Successful” code will always run.
You should note also that the result of the if(okNum($ids)) will wipe whatever value you previously set $input_success to.
It’s hard to say without seeing the okNum method but it looks like this returns true if the array is empty.