w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
PHP objects inside arrays (HOW TO: If array key is 0, return 0. Else if array key is 2, return 2. BASIC LOGIC)

I think the problem is here:

foreach($array as $single) {
    $array = $single->name . ',';
}

$array is only an array the first time the loop is executed as inside the loop your assigning it a new value.

Try this instead:

$names = array();
foreach ($array as $single) {
    $names[] = $single->name;
}
echo implode(', ', $names);




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.