if语句字符串奇怪的比较

时间:2016-08-01 15:27:11

标签: php if-statement

我可能会错过一些东西,但我真的不明白:

public class coffee_list extends ListFragment {

    private ArrayList<coffee> coffeeList;
    private coffee_adapter coffeeAdapter;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        coffeeList = new ArrayList<coffee>();

        coffeeList.add(new coffee("Qaldi Black(Americano)",75.00,0,R.drawable.testicon));

        coffeeAdapter = new coffee_adapter(getActivity(), coffeeList);

        setListAdapter(coffeeAdapter);


        getListView().setDivider(ContextCompat.getDrawable(getActivity(), android.R.color.darker_gray));
        getListView().setDividerHeight(1);
    }
}

显示:

if(trim($_GET[$slug]) == trim($cat->$slug)) {
    $selected = 'selected';
}
else {
    $selected = '';
}

var_dump(trim($_GET[$slug]));
var_dump(trim($cat->slug));
var_dump($selected);

1 个答案:

答案 0 :(得分:2)

应该在if语句中使用$cat->slug而不是$cat->$slug