pdunn Posted September 21, 2006 Share Posted September 21, 2006 Hello I have a minor problem with radio buttons and arrays. I need to get a "Yes" or a "No" from the user. I will use radio buttons just like in the rest of the site. Since these button values depends on the amount of people from the previous form, I have to use an array as the variable.If no information is typed in the second form and I try to verify, I get notices that say that "Notice: Uninitialized string offset: 2 in /home/web/test.php on line 768". That is because no information was written in the array. I get this message when using !isset(array($loop)) and I tried empty() (but that's nearly {less than} the same). array($loop) of uninitialized value will always give me that Notice.I did made a new discovery. Regardless how many items the array is SUPPOSED to have, if at least one is filled in, there is no error. What I meant by SUPPOSED is that if the amount of people is 20, the array should be of size 20. However, if the user only fills in the information for at least 1 person, then there will not be a notice aboutuninitialization string and my error checking works with isset(). However, if none is set, then the problem occurs with isset(), empty(), etc. Any call to array(index) will result in an error since nothing is inside of the array. But if one thing is inside of the error, then the index is simply not set. So, how do I see if anything is in an array? Without printing it out, but just checking.count(), this did not work, it gives the value of 1 and if one item is in the array count() give out 1.Thank you,pdunn Quote Link to comment Share on other sites More sharing options...
printf Posted September 21, 2006 Share Posted September 21, 2006 I can't tell you exactly what is wrong without seeing your code, but in general if you don't know if something will be set or is or is not array you need to test each instance.A simple way to test for an array and if it's not empty is to do![code]if ( isset ( $array[0] ) ) { ... }[/code]It much easier than...[code]if ( isset ( $array ) && is_array ( $array ) && ! empty ( $array ) ) { ... }[/code]What I'm trying to say is that you do testing based on what is expected, not based on guessing!me! Quote Link to comment Share on other sites More sharing options...
pdunn Posted September 21, 2006 Author Share Posted September 21, 2006 Thank you, you were helpful in solving the problem. Using empty($array) is inteligent and I should have thought of that (checking the whole array instead of just indices, especially since I knew that there were no indices).pdunn Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.