是什么导致substr失败?

A simple substr call is not functioning properly. I want to grab only the strings which end with a forward slash. Here are seven strings.

HELLO/NN, SMILE/JJ, JUMP/, GOOD/RB, GREAT/JJ, HAPPY/NNP, SEAPORT/


$m = substr($string, -1);

 if ($m = "/") {
     echo $string;
 }

This code somehow returns true every time. All seven words are printed. I've tried strrev and many other string functions. It doesn't seem to matter. I can literally print $m and see that it's "/" but the if statement decides that every word meets the $m = "/" criteria. Even when $m is not a "/"

The comparison operator is ==, not =:

if ($m == "/") {
     echo $string;
}

Shouldn't that be == rather than =?

if ($m = "/") {

You are assigning the value "/" to $m and that evaluation returns true. You want to compare and should use

if ($m == "/") {