Describes the relationship between php hollow strings and 0, and describes the relationship between php hollow strings.
Preface
Recently, when dealing with latitude and longitude issues, when creating a table, select the string varchar to store the longitude and latitude. This will pave the way for future problems. Let's take a look at the detailed introduction.
$_x=$row["x"];$_y=$row["y"];if(isset($_x) && isset($_y)){ if($row["y"] == 0 || $row["x"] == 0){ $d=$this->getDistance($row["y"],$row["x"],$y,$x); }elseif(!empty($row["y"]) && !empty($row["x"])){ $d=$this->getDistance($row["y"],$row["x"],$y,$x); }else{ continue; } if($d < $radius){ $list[]= $data[$key]; }}
In fact, I want to filter out the data with null longitude and latitude and retain the data with zero longitude or latitude. However, I found that the data with null longitude and latitude is always included when I print the list data.
After studying for a long time, we found that the latitude and longitude fields are character types. $row['y']== 0
PHP performs automatic conversion when judging, so$row['y']== 0
It is correct when null characters are used. Therefore, data with null longitude and latitude is always contained. So how can we remove data with null longitude and latitude?
It is actually very simple as follows:
if(isset($_x) && isset($_y)){ if($row["y"] == "0" || $row["x"] == "0"){ $d=$this->getDistance($row["y"],$row["x"],$y,$x);
Immediately filter out data with null longitude and latitude.
The following describes the code of preg_replace_callback.
$str="sdjfksdf2345";$str=preg_replace_callback ( '/\d{4}/', function ($match){ return $match[0]."ff";}, $str );echo $str;exit;
The code execution result is
sdjfksdf2345ff
This function uses the result of regular expression matching as the parameter of the anonymous function and the returned result as the replacement result.
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.