How to solve this question?

A

Anonymous

Guest
Code:
function check_num($check1="",$check2="",$check3=""){
  $check="$check1,$check2,$check3";
  $turn_array=explode(",",$check);
  while(list($key,$value)=each($turn_array)){
    if (!is_array($value)){
      echo "Please fill in your form properly";
    }
  }
}
check_num(bomb,1,Please);

If the check_num() contains one or more non-array value,it will repeat "Please fill in your form properly"...so how to solve this problem?

Thank you.
 
x_sky58 said:
Code:
function check_num($check1="",$check2="",$check3=""){
  $check="$check1,$check2,$check3";
  $turn_array=explode(",",$check);
  while(list($key,$value)=each($turn_array)){
    if (!is_array($value)){
      echo "Please fill in your form properly";
    }
  }
}
check_num(bomb,1,Please);

If the check_num() contains one or more non-array value,it will repeat "Please fill in your form properly"...so how to solve this problem?

Thank you.

Hi, try using "GetType" with somthing like,

if(GetType($value) == 'sting'), or something like that...

PHP.net
http://se2.php.net/gettype

Best regards,
Paul Peelen
 
I don't think the gettype()will solve the problem because if i put:

Code:
check_num(1,2,text)
,it still okay,and just echo "Please fill in your form properly".

But if I fill like this:
Code:
check_num(text,bomb,3)
,it will repeat "please fill in your form properly" about two times.Emm,i think maybe i use the loop,so it will result like this.But,i really don't know how to change the code,so i need help.

Thank you.
 
x_sky58 said:
I don't think the gettype()will solve the problem because if i put:

Code:
check_num(1,2,text)
,it still okay,and just echo "Please fill in your form properly".

But if I fill like this:
Code:
check_num(text,bomb,3)
,it will repeat "please fill in your form properly" about two times.Emm,i think maybe i use the loop,so it will result like this.But,i really don't know how to change the code,so i need help.

Thank you.

Hi,

If I understand you correctly then it should only show the message where one of the $checks is empty. In that case, try this:
Code:
function check_num($check1="",$check2="",$check3=""){
  $check = "$check1,$check2,$check3";
  $turn_array = explode(",",$check);
  $empty = false;
  foreach($turn_array as $key => $value){
    if (!is_array($value)){
       $empty = true;
    }
  }

  if($empty == true){
    echo "Please fill in your form properly";
  }
}

check_num(bomb,1,Please);
 
Sorry,i think i am asking the wrong question....actually,i want to determine wherther $check1,2,3 are integer or not.If one or more than the value are not integer,then it will only respond:"Please fill in your form properly".

*Value means:
Code:
function check_num(value....)

Now,my brain is going to burst because i can't think one of the suitable function which can help me to determine....

So,TVirus,thank you!@
 
x_sky58 said:
Sorry,i think i am asking the wrong question....actually,i want to determine wherther $check1,2,3 are integer or not.If one or more than the value are not integer,then it will only respond:"Please fill in your form properly".

*Value means:
Code:
function check_num(value....)

Now,my brain is going to burst because i can't think one of the suitable function which can help me to determine....

So,TVirus,thank you!@

Well, In that case... that script will work...

because of:
Code:
   if (!is_array($value)){
      $empty = true;
   }

it will only set the variable $emtpy to TRUE, and therefore you will only get the message one time. Thats the
Code:
  if($empty == true){
    echo "Please fill in your form properly";
  }
code for.

Yours,
Paul Peelen
 
Well..maybe this is a simple question,but i hope somebody can help me to solve this "Mystery"(Hahaha,for me only!)!!

What is the usage of "@"??

Thank you.
 
@ is an error suppressor, when you would like to suppress errors
Its an operator that should be used only when porting to a production enviroment, never in the development phase.
 
so really the code you originally had works.. it just keeps repeating if it errors.. just return out of the function


Code:
<?php
 function check_num($check1="",$check2="",$check3=""){
   $check="$check1,$check2,$check3";
   $turn_array=explode(",",$check);
   while(list($key,$value)=each($turn_array)){
     if (!is_array($value)){
       echo "Please fill in your form properly";
       return false;
     }
   }
 }
 check_num(bomb,1,Please);
?>
 
Hunn... i think we can simplify that:
Code:
<?php

function check_num($arr) {
	foreach($arr as $arr_k => $arr_v) {
		if (!is_array($arr_v)){
			echo "Please fill in your form properly";
			return false;
		}
	}
}

?>
Am i right !?
 
Back
Top