7
After a search, I get the following result:
// O resultado desta linha é I ou II ou III;
echo $subsecao;
// O resultado desta linha é string;
echo gettype($subsecao);
// Faço um switch para atribuir um caso, mas, retorna apenas o default;
switch ($subsecao){
case "I":
$subsecao = "1";
break;
case "II":
$subsecao = "2";
break;
case "III":
$subsecao = "3";
break;
default:
$subsecao = "Não encontrou";
}
// O resultado desta linha é "Não encontrou";
echo $subsecao;
// O resultado desta linha é string;
echo gettype($subsecao);
Why the switch does not work with this scenario?
Makes a
echo "::$subsecao::";and see if there’s no extra room.– Jorge B.
See here at work: http://ideone.com/VhdN7G
– Jorge B.
At this value echo "::$subsecao::"; gave this result ::I :: in this echo $subsecao + "|"; gave this 0
– Alê Moraes
You’re passing an extra space there after
IYou see? The problem is there.– Jorge B.
Because
"I "is different from"I".– Jorge B.
For checks like this, use the Trim on the variable before switching.
– NovoK
It’s bone, programming is a lot of show, but it’s bone. :D. But I used this line $subsecao = preg_replace('/ s+/','$arr[1]);
– Alê Moraes
He tested after that to see if he’s really alone
I? When something doesn’t work always test the inputs and the outputs and if all is well then check the code.– Jorge B.
Before the switch, it is now showing: ::I::, , but after the switch, it looks like this: ::
– Alê Moraes
If it no longer has space it has to work. Experiment with the
II. Is that an I of Equals or is it a lizard l?– Jorge B.
try
switch (trim($subsecao))– KaduAmaral
So @Alêmoraes worked?
– Jorge B.
I edited the question and put at the end the way I did to get to this variable, but still, it didn’t work.
– Alê Moraes
(Trim(strip_tags($subsection)))
– Alê Moraes