Can anyone tell me how I can compare a variable that stores a country with 2 tables in the database?
谁能告诉我如何比较一个存储一个国家的变量与数据库中的两个表?
I have this data in the database:
我在数据库中有这些数据:
country values
PT|AU|USA 0.03|0.04|0.05
And I have a variable that will store one of three values: EN, AU, USA I would like this to get the data from the two tables but in the correct order.
我有一个变量,它将存储三个值中的一个:EN,AU,USA我希望这样从两个表中获取数据,但顺序正确。
PT => 0.03
AU => 0.04
USA => 0.05
I tried this way but it didn't work
我试过这种方式,但它没有用
$countries = $get1x["country"];
$values = $get1x["values"];
$tags = explode('|' , $countries);
$tags2 = explode('|' , $values);
$country = "";
$value = 0.0;
foreach($tags as $i => $key) {
$i > 0;
$value = str_split($key, $ii);
}
foreach($tags2 as $i2 => $key2) {
$i2 > 0;
$value = str_split($key2, $iii);
}
print_r($country);
Can anyone tell me a way?
有谁能告诉我一个方法?
1 个解决方案
#1
1
You can useexplode
and array_combine()
, i.e:
你可以使用explode和array_combine(),即:
$countries = explode("|", "PT|AU|USA") ;
$values = explode("|", "0.03|0.04|0.05") ;
$combined = array_combine($countries, $values);
print_r($combined);
Array
(
[PT] => 0.03
[AU] => 0.04
[USA] => 0.05
)
#1
1
You can useexplode
and array_combine()
, i.e:
你可以使用explode和array_combine(),即:
$countries = explode("|", "PT|AU|USA") ;
$values = explode("|", "0.03|0.04|0.05") ;
$combined = array_combine($countries, $values);
print_r($combined);
Array
(
[PT] => 0.03
[AU] => 0.04
[USA] => 0.05
)