user2818060
user2818060

Reputation: 845

How to Make values of Array Comma separated

What I need:

problem im facing :

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

Answers (3)

Girish
Girish

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

Clément Malet
Clément Malet

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

Zentoaku
Zentoaku

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

Related Questions