-1

I have this function :

$array = $um_followers->api->following( $currentid );

If I tried a var_dump :

var_dump($um_followers->api->following( $currentid ));

This is the result :

array(2) { [0]=> array(1) { ["user_id1"]=> string(1) "1" } [1]=> array(1) { ["user_id1"]=> string(2) "44" } }

1) I want to display the data 1 and 44 in the same line

2) I want to display the data 1 and 44 in the same line with a coma

Mathieu
  • 797
  • 2
  • 6
  • 24

2 Answers2

1

you can do

echo implode(' ', array_column( $array,'user_id1')); 
echo implode(', ', array_column( $array,'user_id1')); // with comma
ArtOsi
  • 913
  • 6
  • 13
  • Thank you but I am using an older version of php – Mathieu Aug 16 '17 at 14:28
  • What version are you using? – B001ᛦ Aug 16 '17 at 14:37
  • if you need to get values of 'user_id1' column only and using php version below 5.5 you can use [array_map](http://php.net/manual/en/function.array-map.php) `$newArray = array_map(function($element) { return $element['user_id1']; }, $array);` – ArtOsi Aug 16 '17 at 14:38
0

well, something like this?

$array = array(
    array("user_id1" => 1),
    array("user_id1" => 44),
);

$line1 = "";
$line2 = "";
foreach($array as $smallArray){
    $line1 .= $smallArray['user_id1'].' ';
    $line2 .= $smallArray['user_id1'].', ';
} 
$line1 = substr($line1, 0, -1); //delete last ' '
$line2 = substr($line2, 0, -2); //delete last ', '

echo $line1.'<br>';
echo $line2.'<br>';

it will echo this:

1 44
1, 44
Anchor_Chisel
  • 166
  • 1
  • 8