Describes the relationship between php hollow strings and 0, and describes the relationship between php hollow strings.

Source: Internet
Author: User

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']== 0It 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.