phpstringvariablesseparator

PHP combining variables


I have a 'foreach' PHP loop. Each time the loop is run, I am combing the value in the current loop iteration ($CurrentTillID) to a variable.

Here is my code:

$separator = ',';
$tillDetails = $tillDetails . $CurrentTillID;

I am wanting to add a separator between each $CurrentTillID value.

This is the code that I have tried:

$tillDetails = $tillDetails . $CurrentTillID . $separator;

This above code does not work. Can I please have some help to get this working?

Thanks in advance.


Solution

  • Try putting the separator in between the items you are separating.