strlen in if else语句不起作用

i have a array called $answer when i print in using print_r Result is this

Array (
    ['answer1'] => 0 
    ['answer2'] => 1
    ['answer3'] => 0
    ['answer4'] => 1
    ['answer5'] => 0
    ['answer6'] => 1
)

in if else statement i cant understand the logic

if (strlen($answers["amswer1"]) === '1' && strlen($answers["amswer2"]) === '1' && strlen($answers["amswer3"]) === '1' && strlen($answers["amswer4"]) === '1' && strlen($answers["amswer5"]) === '1' && strlen($answers["amswer6"]) === '1') {
     echo 'here i am';
}else{
     print_r($answers);
}

but the result is always false..

strlen return length of string i.e of type integer and you doing a strict comparison with a type string so it will return false.

if (strlen($answers["answer1"]) === 1 && strlen($answers["answer2"]) === 1 &&            
   strlen($answers["answer3"]) === 1 && strlen($answers["answer4"]) === 1 && 
   strlen($answers["answer5"]) === 1 && strlen($answers["answer6"]) === 1)
{
   echo 'here i am';
}
else{
  print_r($answers);
}

Again you have a typo too in your array keys.

check you cheking with wrong keys it's answer not amswer Also use equals to == operator to match else you need to change match conditions (like '1' to 1 ) or need to change value type of array elements(like 0 to "0") for all

if(strlen($answers["answer1"]) == '1' && strlen($answers["answer2"]) == '1' && strlen($answers["answer3"]) == '1' && strlen($answers["answer4"]) == '1' && strlen($answers["answer5"]) == '1' && strlen($answers["answer6"]) == '1') { 
  echo 'here i am';
}else{
   print_r($answers);
}

or

if (strlen($answers["answer1"]) === 1 && strlen($answers["answer2"]) === 1 && strlen($answers["answer3"]) === 1 && strlen($answers["answer4"]) === 1 && strlen($answers["answer5"]) === 1 && strlen($answers["answer6"]) === 1) {
   echo 'here i am';
}
else{
  print_r($answers);
}

You have a typo in this line :

strlen($answers["amswer1"])

use answer1 instead of amswer1 in your query!! :)

strlen($answers["answer1"])

that should do!

you use the === here which is use for equality of type match may be your work can done by == sign in comparision because strlen return int by default so you compare it with string

You Have two mistakes here

  1. when you print_r the $answer it shows

    Array ( [answer1] => 0 [answer2] => 1 [answer3] => 0 [answer4] => 1 [answer5] => 0 [answer6] => 1 )

    but you are using $answers["amswer1"]) === '1'

    so in the the key you have spelling mistake [amswer1] please correct it [answer].

  2. you are using '===' its check equality with restriction of data type of value means there is difference between '1' and 1.

    '1' denotes character

    1 denotes integer

so be careful when using strlen function because it returns integer.