There is a code

<?php $a = array(1, 1, 2, 3, 4, 5, 15); $b = implode('', $a); $r = trim($b, '15'); echo $r; ?> 

Can you explain why the result will be 234?

  • It removes characters 1 and 5 - Yuri
  • removes all edinichki and five php.net/manual/ru/function.trim.php - Jean-Claude
  • I thought so too, but if $ r = trim ($ b, '14'); then the result is 234515. Four for some reason remains. - Beginner
  • @Sven Wrong question asked! :) Now, if you asked what the result would be, then more interesting. When you have already given the answer, everyone will tell you that characters 1 and 5 are deleted from the line. :) - Vlad from Moscow
  • So what really happens? how does it work then? - Beginner

1 answer 1

According to the description found on the Internet :),

There are no frills and colors. Specifies the character (s) to remove. Without this remove the following "" an ordinary space

The trim function removes the starting and ending characters according to the specified pattern as a string. For example, for a code snippet

 $a = array(1, 1, 2, 3, 4, 5, 15); $b = implode('', $a); $r = trim($b, '14'); 

the initial '1' will be removed and the result will be

 '234515' 

The characters '4' and '1', which are inside the string, will not be deleted, as they are not the starting or terminating character of the string.

And for this fragment, the code

 $a = array(1, 1, 2, 3, 4, 5, 15); $b = implode('', $a); $r = trim($b, '15'); 

will be the result

 '234'