<?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = 'root';
$dbPassword = '1234fedf';
$dbDatabase = 'smsmobile';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");
$sql = "SELECT destinationaddress FROM reporting";
//print $sql;
$queryRes1 = mysql_query($sql);
while($rows=mysql_fetch_assoc($queryRes1))
{
$destinationaddress[] = $rows['destinationaddress'];
}
$phones = $destinationaddress;
$sqlprefix = "SELECT country,prefix FROM countrycodes";
//print $sqlprefix;
$queryprefix = mysql_query($sqlprefix);
while($data=mysql_fetch_array($queryprefix))
{
$countryarray[] = $data['country'];
$prefixarry[] = $data['prefix'];
}
$countryname = implode(',',$countryarray);
//print $countryname;
$prfixname = implode(',',$prefixarry);
//print $prfix;
$countrycode = $countryname;
$prfix = $prfixname;
foreach($countryname as $key => $value){
$result[] = 'country : '.$value.' prefix:'.$prfix[$key];
}
$allstring = implode(',', $result);
print_r( $allstring );
?>
答案 0 :(得分:0)
转换字符串中的数组首先将u&#39; r结果数组内容转换为字符串
$ countrycode = implode(&#39;,&#39;,$ countryarray);
$ prfix = implode(&#39;,&#39;,$ prefixarry);
答案 1 :(得分:0)
例如,您的数组有一些数据。你可以在字符串中implode
数组,见下文
$countryarray = array('Pakistan', 'India');
$prefixarry = array(971, 43);
$countrycode = $countryarray;
$prfix = $prefixarry;
foreach($countryarray as $key => $value){
$result[] = 'country : '.$value.' prefix:'.$prfix[$key];
}
$allstring = implode(',', $result);
print_r( $allstring );
结果:
country : Pakistan prefix:971,country : India prefix:43