Hello I'm new here on this forum.
I was wondering if someone could help me out here. I'm following an IT study currently and one of the subjects I have trouble with is PHP programming. I currently have problem with the following question.
Question : Create a function that checks the values(numbers) in an array. If the current value is bigger than or equals to the one before that, it should echo true. If not, echo false.
True example: $array = array (1,2,2,3,4) this should say true 4 times because it gets bigger & the number stays the same.
False Example: $array = array (1,2,1,4) this should say false because the number is going down.
I have made the following code and it will always return "true".
$input = array (1,4,2,7);
function trueorfalse (array $input){
foreach ($input as $key => $value){
$value >= $key[0];
print "true";
}
}
trueorfalse($input);
I have not idea how to compare the current value the foreach loop is at, with the value before that. Any ideas?
PS: PHP is new for me and I really have trouble figuring out how to come up with ideas on how to solve a question.
Yours truly,
Joey Benning IT student Windesheim Zwolle (Netherlands).