How would I check if an array(with three values) that was passed to a function from another file has all three values?
For example I want to get an error if someone puts in $ids=Api_Books_Book::getTest(array(1,2,)); (There is no value on the the third key/index).
this is my code so far
public static function getTest($ids){
$input_result = array(
);
foreach ($ids as $id) {
$input_result['result']['Id '.$id] = $id;
}
if((array_key_exists('0',$ids))){
echo "You have inputted some data in the Api_Books_Book::getTest<br/>";
$input_success = "Successful!";
}
else
{
echo "There is no data<br/>";
$input_success = "Not Successful";
}
$result=array('status'=>$input_success,
'message'=>"some errors will be displayed here",
'result'=> $input_result
);
rdie($result);
return $result;
}
If you have simple numerically indexed arrays, the only thing that makes sense is
count:or:
You can use
$array = array_values($array)to reset the numeric keys to make sure the values are at index[0],[1]and[2]and not any other indexes.If you have key => value pairs and you expect certain keys to be set, use
array_diff_key: