Display the elements which has 5 on the right side(right most).
Input :{55,4,121,3333,65}
Output:{55,65}
2)display all the elements which has 2 digits in the first position and rest as it is.
Input:{122,3333,44,77777,9,13,5555}
Output:{44,13,122,3333,77777,9,5555}.
Please help me out. try to give answer in php.
Sounds like something fun I would have to do in school. Here's the code fresh off the press!
Working demo (until I remove it): http://blazerunner44.me/test/fun.php
Question 1:
function question1($input){
$result = array();
foreach($input as $number){
$numberString = (string)$number;
$lastNumber = (int)substr($numberString, -1);
if($lastNumber == 5){
array_push($result, $number);
}
}
return $result;
}
$answer1 = json_encode(question1(array(55,4,121,3333,65)));
echo($answer1);
Question 2:
function question2($input){
$result = array();
foreach($input as $number){
$numberString = (string)$number;
if(strlen($numberString) >= 2){
array_push($result, $number);
}
elseif($numberString[0] == $numberString[1]){
array_push($result, $number);
}
}
return $result;
}
$answer2 = json_encode(question2(array(122,3333,44,77777,9,13,5555)));
echo($answer2);
Since your question wasn't very specific, let me know if you need me to explain how something works.