php条件代码显示与预期不同的结果

时间:2017-10-24 11:22:55

标签: php

如果条件为真,此代码应以绿色打印结果,而是打印出蓝色[如“' else'码]

<?php
$col = null;

$chek = 51200;
$chek -= 5200;

if ($chek / 1000 == 0 && (($chek % 10000) * 2) == 12000) {
    $col = "style='color:green;'";
    $save .= "$co . $a1 * $b1 = $span $col> $l </span> </br> </br>";
} else {
    $col = "style='color:blue;'";
}
$res = "<span $col> $chek </span>";

echo $res;

4 个答案:

答案 0 :(得分:3)

if($chek / 1000 == 0

的问题

因为46000/1000!= 0

我想你想把!=而不是==

我希望我能帮助你:)。

答案 1 :(得分:0)

$chek / 1000 = 46,而不是0;因此if语句失败。

如果您更改

,则代码有效

if ($chek / 1000 == 0 && (($chek % 10000) * 2) == 12000) {

if ($chek / 1000 == 0 || (($chek % 10000) * 2) == 12000) {

答案 2 :(得分:0)

更改您的代码:

{ // Draw Polyline
            Double myLat, myLon;
        Double myStartLat,  myStartLon;
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            while ( cursor.moveToNext()) {
                try {myLat =  Double.valueOf(cursor.getString(cursor.getColumnIndexOrThrow(COL_LAT)));}
                catch (NumberFormatException e) { myLat=0.0d;}
                try {myLon =  Double.valueOf(cursor.getString(cursor.getColumnIndexOrThrow(COL_LON)));}
                catch (NumberFormatException e) { myLon=0.0d;}
                polyline=new LatLng(myLat,myLon);
                polylines.add(polyline);
                if (cursor.getPosition() == 0)  { // start and end of the road
                    myStartLat=myLat;
                    myStartLon= myLon;
                    mapAddMArker(googleMap,polyline,0); // add a marker last arg = 0 = start
                }else {
                    if (cursor.isLast()) { // start and end of the road
                        mapAddMArker(googleMap, polyline, 9); // add a marker
                    }
                }
                builder.include(polyline); // extends bounds to include all the road
            }
            PolylineOptions poly = new PolylineOptions()
                    .addAll(polylines)// https://stackoverflow.com/questions/22516015/polyline-not-visible-android-maps-api-v2
                    .color(Color.RED)
                    .width(5)
                    .visible(true)
                    .zIndex(0); // before = 30
            googleMap.addPolyline(poly);
            LatLngBounds bounds = builder.build();
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0); // last argument = padding i
            googleMap.animateCamera(cu); // EXCEPTION HERE
        // I tried this, it works but it is not what I want to display googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(myStartLat, myStartLon), 15)); 
 }

为:

if ($chek / 1000 == 0 && (($chek % 10000) * 2) == 12000) 

希望它会对你有所帮助。

答案 3 :(得分:0)

if ($chek / 1000 == 0 && (($chek % 10000) * 2) == 12000) {

if ($chek / 1000 != 0 && (($chek % 10000) * 2) == 12000) {