Jump to content

string code on php ?


asmith

Recommended Posts

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? )

 

 

Link to comment
https://forums.phpfreaks.com/topic/82776-string-code-on-php/
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/82776-string-code-on-php/#findComment-421025
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.