简体   繁体   English

来自 PHP 数组的 Unset() 值以防止打印到屏幕

[英]Unset() value from PHP Array To Prevent Print Out To Screen

I'm a jr developer working on a wordpress plugin that uses an API to retrieve data for the site.我是一名 jr 开发人员,致力于使用 API 检索站点数据的 wordpress 插件。 Within the API call are latitude and longitude values for the Google maps API on the same page. API 调用中包含同一页面上 Google 地图 API 的纬度和经度值。 There is a for loop to print each provided value from the API.有一个 for 循环来打印 API 提供的每个值。 I would like to stop this loop from printing the provided latitude and longitude values to the screen while still providing those values to the Google Map.我想阻止此循环将提供的纬度和经度值打印到屏幕,同时仍将这些值提供给 Google 地图。 A few solutions come to mind but I'm not certain which is the best solution... 1.) Unset() the latitude and longitude values at the point of the for loop.我想到了一些解决方案,但我不确定哪个是最好的解决方案...... 1.) Unset() 在 for 循环点的纬度和经度值。 Perhaps this will prevent it from applying the values to the Google Map API?也许这会阻止它将值应用于 Google Map API?

2.) Within the for loop set an if statement to watch for those two values - but this would be checking for the values every time one of the many fields are looped through, does this solution take away from the performance/speed of the website? 2.) 在 for 循环中设置一个 if 语句来监视这两个值 - 但这将在每次循环许多字段之一时检查值,此解决方案是否会影响网站的性能/速度?

Thank you in advance先感谢您

I hope array map is what you looking for我希望数组映射是你要找的

$in=[
[
    'BathsFull' => 2, 
    'BathsHalf' => 1, 
    'BathsTotal' => 3, 
    'BedsTotal' => 4, 
    'Latitude' => 96.794636, 
    'Longitude' => -96.828915, 
    'ListPrice' => 729900
 ],
 [
    'BathsFull' => 2, 
    'BathsHalf' => 1, 
    'BathsTotal' => 3, 
    'BedsTotal' => 4, 
    'Latitude' => 96.794636, 
    'Longitude' => -96.828915, 
    'ListPrice' => 729900
 ]
];
print_r($in);
$out = array_map(function (array $arr) {unset($arr['Longitude'],$arr['Latitude']);return $arr;}, $in);
print_r($out);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM