I am trying to find the last element in the array by using foreach loop.
I have..
foreach ( $employees as $employee ) {
$html.=$employee ->name.'and ';
}
I don’t want to add ‘and’ to the last employee. Are there anyways to do this? Thanks a lot!
There’s another way, I suppose:
It’s simple: array_map will create an array of
$employee->nameelements, and implode will make a string from these, using' and 'string as ‘glue’. )