Reputation: 845
What I need:
number separated by (,) .
like : 42166 ,42167 , 42168,42169 etc.
problem im facing :
the number is not appended by(,).
im using implode function.
Array Structure:
Array
(
[id] => 42166
[Company_Website] => http://www.amphenol-highspeed.com/
[company_name] => Amphenol High Speed Interconnect
[city_name] => New York
[country_name] => USA
[comp_img] =>
)
42166Array
(
[id] => 42167
[Company_Website] => http://www.clearfieldconnection.com/
[company_name] => Clearfield, Inc.
[city_name] => Plymouth
[country_name] => USA
[comp_img] =>
)
Php Code:
foreach ($result as $key=>$value) {
echo $company_id= implode(",",(array)$value['id']);
}
output im getting: 412664127741288 etc.
Upvotes: 0
Views: 80
Reputation: 12127
If you want to convert Id
values into comma separated then0 try by string manipulation and append comma (,) with each id value
$company_id = ""
foreach ($result as $key=>$value) {
$company_id .= $value['id'].",";
}
echo rtrim($company_id, ",");
Upvotes: 0
Reputation: 5090
foreach ($result as $key=>$value) {
$company_id[] = $value['id'];
}
$company_id = implode (',', $company_id);
Edit : Sorry that I misread your question at first time
Upvotes: 1
Reputation: 767
$i=0;
$company_id = "";
foreach ($result as $key=>$value) {
$company_id .= ($i==0)?$value['id']:','.$value['id'];
$i++;
}
echo $company_id;
Upvotes: 1