gibigbig Posted April 7, 2010 Share Posted April 7, 2010 i have four variables and i want to execute a script only of these four variables have values in them, how can i do this? Link to comment https://forums.phpfreaks.com/topic/197815-how-to-check-if-only-one-value-in-an-array-is-missing/ Share on other sites More sharing options...
five Posted April 7, 2010 Share Posted April 7, 2010 maybe this will do if ( (isset($a)) && (isset($b)) && (isset($c)) && (isset($d)) ) { // your code here Link to comment https://forums.phpfreaks.com/topic/197815-how-to-check-if-only-one-value-in-an-array-is-missing/#findComment-1038078 Share on other sites More sharing options...
teamatomic Posted April 7, 2010 Share Posted April 7, 2010 Not sure axactly what you want as your explanation is a bit lacking. in your subject you mention an array. in your post text you only mention variables. So maybe... $a=array(a,b,c,d,e,f,g,h,i,j); $b=array(a,b,c,z);//drop the z to see ~found~ $y=array_intersect($a,$b); $z=array_diff($b,$y); if(count($z)==0) echo "found"; else echo "not found"; HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/197815-how-to-check-if-only-one-value-in-an-array-is-missing/#findComment-1038082 Share on other sites More sharing options...
gibigbig Posted April 7, 2010 Author Share Posted April 7, 2010 maybe this will do if ( (isset($a)) && (isset($b)) && (isset($c)) && (isset($d)) ) { // your code here does not work Not sure axactly what you want as your explanation is a bit lacking. in your subject you mention an array. in your post text you only mention variables. So maybe... $a=array(a,b,c,d,e,f,g,h,i,j); $b=array(a,b,c,z);//drop the z to see ~found~ $y=array_intersect($a,$b); $z=array_diff($b,$y); if(count($z)==0) echo "found"; else echo "not found"; HTH Teamatomic ok i have four variables and i want a query to execute ONLY if ALL four variables have something stored in them. Link to comment https://forums.phpfreaks.com/topic/197815-how-to-check-if-only-one-value-in-an-array-is-missing/#findComment-1038096 Share on other sites More sharing options...
gibigbig Posted April 7, 2010 Author Share Posted April 7, 2010 this is my code so far: if ( (isset($newinfo)) && (isset($gibid)) && (isset($type)) && (isset($full_type)) ) { $query1 = "UPDATE formresults SET sdata = '".$newinfo."' WHERE userid = ".$gibid." AND fid='".$fid."' And title = '".$full_type."'"; mysql_query($query1); echo "<html><body><meta http-equiv='refresh' content='2;url=####url here#####p'>Edited sucessfully for user ".$gibid." on form ".$fid." with the title ".$full_type." and the message is<p>".$newinfo."</p></body></html>"; } else {echo "not allowed"; }; Link to comment https://forums.phpfreaks.com/topic/197815-how-to-check-if-only-one-value-in-an-array-is-missing/#findComment-1038097 Share on other sites More sharing options...
teamatomic Posted April 7, 2010 Share Posted April 7, 2010 if all the vars do in fact exist but some might be empty isset will not work but if($var1 != '' && $var2 != '') will. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/197815-how-to-check-if-only-one-value-in-an-array-is-missing/#findComment-1038099 Share on other sites More sharing options...
gibigbig Posted April 7, 2010 Author Share Posted April 7, 2010 if all the vars do in fact exist but some might be empty isset will not work but if($var1 != '' && $var2 != '') will. HTH Teamatomic thank you teamatomic works perfectly Link to comment https://forums.phpfreaks.com/topic/197815-how-to-check-if-only-one-value-in-an-array-is-missing/#findComment-1038100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.