我在"countries.php“中列出了所有国家/地区的名称,例如:
<?php
$countryArray = array(
'AD'=>array('name'=>'ANDORRA','code'=>'376'),
'AE'=>array('name'=>'UNITED ARAB EMIRATES','code'=>'971'), ...
);
function countrySelector($defaultCountry = "", $id = "", $name = "", $classes = ""){
global $countryArray; // Assuming the array is placed above this function
$output = "<select id='".$id."' name='".$name."' class='". $classes."'>";
$output .= "</select>";
}使用"signup.php“中的文件,这很好地工作,但是,我想做的是在"signup.php”中创建输入(手机号码),在移动输入中,我想使用一个国家代码当用户选择一个国家时,它会将国家代码插入到移动输入中。喜欢:用户选择US +1..在另一个输入中,它将显示+1(用户可以输入自己的号码,而不需要自己添加国家代码),我也正确地进行了移动验证。我不知道怎么写代码。请帮帮忙。
发布于 2019-05-09 22:08:46
你应该好好读一读课程。如果在类中定义脚本,则可以通过以下方式访问变量:首先调用use myClass,然后静态访问变量,或者创建类对象的实例。
例如,在这里,您应该创建Country类,并将$countryArray作为可以使用Country::$countryArray访问的类中的静态变量
这是你的Country类的样子:
class Country {
public $countryArray = ['usa', 'canada'];
} 然后在你的另一个脚本中,你可以这样做:
use Country;
$countries = Country::$countryArray;https://stackoverflow.com/questions/56061174
复制相似问题