PHP Array Variables Case Sensative

Viewed 10

I have created a simple form which checks if the entered name is within the array. The code works but the user has to be case specific. for example.... if i type in rich instead of Rich then it will come up as i dont know you. is there anyway to make the php code disgard the case of the letter? code below

<?php

    if ($_POST) {
        
        $family = array("Rich", "Kate", "Tony", "Robert");
        
        $isKnown = false;
        
        foreach ($family as $value) {
            
            if ($value == $_POST['name']) {
                
                $isKnown = true;
                
            }  
            
        }
        
        if ($isKnown) {
            
            echo "Hi there ".$_POST['name']."!";
            
        } else {
            
            echo "I don't know you.";
            
        }      
        
    }


?>



<form method="post">

    <p>What is your name?</p>
    
    <p><input type="text" name="name"></p>
    
    <p><input type="submit" value="Submit"></p>


</form>
0 Answers
Related