PHP数组打印语句

时间:2012-05-17 11:20:26

标签: php

这是我的代码:

        if(is_file($userName.".txt")) {
            $userDetails = explode(',', file_get_contents($userName.".txt"));
            print($userDetails[0]);
            if ($password == $userDetails[0]) {
                print('Correct login');
            } else {
                print('Incorrect login');
            }
        }

我有以下文件:Simon.txt,内容如下:simonpassword,4,1 如果$ userName是'Simon',那么当代码运行时,如何打印4而不是simonpassword:print($ userDetails [0])?

1 个答案:

答案 0 :(得分:0)

<?
$userName = "Simon";
$password = "simonpassword";
if(is_file($userName.".txt")) {
        $userDetails = explode(',', file_get_contents($userName.".txt"));
        print($userDetails[0]);
        if ($password == $userDetails[0]) {
            print('Correct login');
        } else {
            print('Incorrect login');
        }
    }
?>

这是Simon.txt

simonpassword,4,1

它有效。