asmith Posted December 22, 2007 Share Posted December 22, 2007 hmm seems i have a problem with these php codes : while ( // some expression { $a .= $b.' && '; } $finala = substr($a,0,-4); if ($finala == 3 ) {//do stuff } the if statement seems do not working, i get some values from sql (which are int) . put them after each other like you see in the code : 2 && 5 && 4 &&... then i remove the 4 letters from the end which is " && " . then check all of them if they are equal to something. but the above code seems not working. i put a echo there ,and saw that substr is not working and won't remove . i changed that line in while to : $a .= '$b'.' && '; but do not work either . how can i solve it ? (i guess maybe i'm comparing a string to int? ) Quote Link to comment https://forums.phpfreaks.com/topic/82776-string-code-on-php/ Share on other sites More sharing options...
Northern Flame Posted December 22, 2007 Share Posted December 22, 2007 how about if($finala == '3 && '){ // do stuff } Quote Link to comment https://forums.phpfreaks.com/topic/82776-string-code-on-php/#findComment-421016 Share on other sites More sharing options...
asmith Posted December 22, 2007 Author Share Posted December 22, 2007 nah wont work . the incoming value to final a is like : $aaa && $bbb && $ccc ... these varilable all must match the part in if statement , so it can't be 3 && . this " && " is a php definition code . i'm using it as a string :/ Quote Link to comment https://forums.phpfreaks.com/topic/82776-string-code-on-php/#findComment-421020 Share on other sites More sharing options...
Northern Flame Posted December 22, 2007 Share Posted December 22, 2007 how about you use if($finala[0] == 3){ // do stuff } when you dont establish an array and you ask it to take the [0] of a variable it takes the first character of the output Quote Link to comment https://forums.phpfreaks.com/topic/82776-string-code-on-php/#findComment-421022 Share on other sites More sharing options...
asmith Posted December 22, 2007 Author Share Posted December 22, 2007 oh i get it now the first time it worked , not fine . just run the if statement , i was wondering about it . so it took the first character ! you mean i put the string in an array , then check the first key in the array ? let me explain it more clear, in mysql data base , in a column , i've got some numbers in some rows . like : column 4 4 3 4 2 that while loop fetch this column records . and put it on the $a you saw , so for example in this case $a would be : 4 && 4 && 3 && 4 && 2 && , then i remove the last 4 characters . it will be : 4 && 4 && 3 && 4 && 2 the i campre it to a value in if statement . for example : if (4 && 4 && 3 && 4 && 2 == 4 ) which it isn't . so any better idea ? thanks for taking time Quote Link to comment https://forums.phpfreaks.com/topic/82776-string-code-on-php/#findComment-421025 Share on other sites More sharing options...
Barand Posted December 22, 2007 Share Posted December 22, 2007 I don't understand the purpose of your if statement if (4 && 4 && 3 && 4 && 2 == 4 ) Are you trying to test if "4" was in the list of values retieved from the db table? Quote Link to comment https://forums.phpfreaks.com/topic/82776-string-code-on-php/#findComment-421138 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.