0

I have a 2d array that looks like this :

[0] => stdClass Object
    (
        [ProfileID] => SomeID
        [Practice_Name] => Test Practice
        [Telephone] => SomeNum
        [Email] => SomeEmail
        [Contact_Name] => SomeContact
        [Address] => 
        [City] => 
        [State] => 
        [ZipCode] => 
        [Verification_Status] => 
        [Last_Accessed] => 
    )

So I would like to print each array as "SomeID, Test Practice, SomeNum....." and then on the next line print the next array values.

I looked into this question - Extract value from multidimensional array and place in comma separated string. But i was wondering if there is a way to do it without having to explicitly pass the field name for each like ProfileID, Practice Name, etc.

Community
  • 1
  • 1
raeq
  • 971
  • 4
  • 15
  • 36

3 Answers3

1

As you have an object and not an array, so you need to hard convert it using (array), example:

foreach($rowSet as $row) {
    echo implode(",", (array) $row) . PHP_EOL;
}
0
<?
$string = "";
foreach($array as $piece){
if($string != ""){$string .= ",";}
$string .= $piece;
}
?>
Vilsol
  • 722
  • 1
  • 7
  • 17
0

This code is untested:

PHP

<?php
$array_keys = "";
$array_values = "";

foreach($array as $element):
    $array_keys.= array_keys($element).', ';
    $array_values.= $array[$element]
endforeach;

?>
Community
  • 1
  • 1
Jeff Noel
  • 7,500
  • 4
  • 40
  • 66