0

How can I prevent the vertical bar from being displayed at the end of array that I have selected?

enter image description here

I would simply like to remove the pipe-separator from the end.

 $Field = trim($_POST['seleField']);
        if($Field == 'OrderDay'){
            $Value = '';
            foreach($_POST['day'] as $selected){
                $Value .= trim($selected) ."|";
            }
        }
David Buck
  • 3,752
  • 35
  • 31
  • 35
ayiqa
  • 15
  • 4
  • 1
    use `rtrim` to remove | from the end of data. – Devsi Odedra Jan 20 '20 at 04:13
  • Does this answer your question? [How do I remove all specific characters at the end of a string in PHP?](https://stackoverflow.com/questions/2053830/how-do-i-remove-all-specific-characters-at-the-end-of-a-string-in-php) – user3783243 Jan 20 '20 at 04:19

1 Answers1

1

You don't need a loop, just join all values using implode(), no pipe at the end.

 $Field = trim($_POST['seleField']);
    if($Field == 'OrderDay'){
        $Value = implode('|', $_POST['day']);
    }
Triby
  • 1,739
  • 1
  • 16
  • 18