检查 PHP 中包含文件中的数组键值


Check array Key Value in included file in PHP

请帮助我从 php 中包含的文件中找出数组键值。

城市.txt具有以下值:

array('mumbai'=>70624,'delhi'=>69514);

主 PHP 文件:

$verified_city = include('city.txt');
$city_nm = 'delhi';
if(array_key_exists($city_nm, $verified_city))
{
     echo "Exists";
}
else
{
     echo "Not Exists";
}

它正在进入其他部分。

你的city.tx应该是一个城市.php你在其中做

<?php
   $verified_city = array('mumbai'=>70624,'delhi'=>69514);
?>

(在 main.file 中,您只需include('city.php');或者它可以是一个 .您阅读并分配给$verified_city的 CSV .