问题描述
date_default_timezone_set('Asia/Kolkata');
header('Access-Control-Allow-Origin: *');
include_once('conn.PHP');
$data2 = array();
$content = trim(file_get_contents("PHP://input"));
$data = json_decode($content);
$couplenumber = $data->contact_number;
$sql = "SELECT * from `users_table` where `phone` IN '$couplenumber'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
array_push($data2,$row);
}
echo json_encode($data2);
} else {
echo 0;
}
$conn->close();
$couplenumber
是一个包含多个联系电话的数组。我想将数组值匹配到名为phone的表列。电话的字符串值表示单个联系人。将电话值匹配到多个$couplenumber
值的联系人后如何获取数据?
解决方法
如果您向我们展示数组内容,那就更好了。但是,如果您有一些东西,例如一个对象数组和一个仅带有id的数组,让我们尝试一下:
//Arrays are like :
$tab1 = [3,4];
//Considering Object is a class which receive id in constrictor and has et getId method.
$obj1 = new Object(1);
$obj2 = new Object(2);
$items = [$obj1,$obj2];
$tab2 = [];
foreach ($items as $item) {
$tab2[] = $item->getId();
}
$diff = array_merge(array_diff($tab1,$tab2),array_diff($tab2,$tab1));
// True there are same,false there differents.
var_dump( empty($diff) && (count($tab1) === count($tab2)) );