-2
function findIntInStr($str=''){
$str = 'abc123';
for($i=0;!empty($str[$i]);$i++)
    {
        if(is_numeric($str[$i]))
        {   
            return false;
        }
    }
    return true; }

This question was asked by me in an interview. This was my answer, However the interviewer asked me to check the datatype of character without using any built-in function. How can I do that here?

imrahul
  • 41
  • 6
  • Hi, please edit the question to identify the experiments/research you have done and why these didn't help. Please remember that this is not a code-writing service. Thanks. – MandyShaw Oct 17 '18 at 20:41
  • Can you use the built-in `strlen()` function? If not, I think you're out of luck. – Barmar Oct 17 '18 at 20:59
  • Loop through all the characters in the string. If it matches `0`, `1`, `2`, etc. return `false`. If you get to the end of the loop, return `true`. – Barmar Oct 17 '18 at 21:01
  • The whole point of exercises like this is to teach you how to figure out algorithms on your own. Asking for help on SO is defeating the purpose. Programming is a creative process, not just copying things others have done. – Barmar Oct 17 '18 at 21:03
  • Thankx for your feedback #Barmar. – imrahul Oct 18 '18 at 06:54
  • I was expecting some intelligent answer. – imrahul Oct 20 '18 at 20:20

1 Answers1

0
function findIntInStr($str=''){
$str = 'abce234';
for($i=0;!empty($str[$i]);$i++)
    {
        if((string)(int)$str[$i] === (string)$str[$i] )
        {   
            return false;
        }

    }

    return true;}
imrahul
  • 41
  • 6
  • 1
    try your code with `findIntInStr('01234')`. I don't think it will yield the expected result ^^ – Alfwed Oct 18 '18 at 12:48
  • Yes, you are right, It is not giving the expected result in the case of 0, can you suggest a perfect solution. – imrahul Oct 18 '18 at 14:12