in my website's registration form, the following php code controls user first name field :
if (!isset($value[4])){
$return = $register_msg['_register_some_msg'];
}
what does this code do ? does it have anything with checking the string length ? currently it forces the first name of minimum 3 characters, but as i searched seems that strlen()
Function checks the length of string which doesn't exists there.
The isset()
method here just verify if $value[4]
(your object, or string, or other) exists or not.
Yes, this code is checking string length.
It appears you have two arrays.
$value
is a numerical array, and you check if the 5th element is set. (index starts on 0).
$register_msg
is an associative array, instead of numbers as the index, it uses keys. Here you assign the value of key _register_some_msg
to your return variable.
The other option is that $value
is a string, and it's using bad practice to check each letter by referencing them as an array key:
<?php
$x = 'abcd';
echo $x[3];
//output: d
Which is just bad. use strlen()
instead http://php.net/manual/en/function.strlen.php