note 128729 added to function.implode
| From: | alessandro dot a dot rosa at gmail dot com | Date: | Thu, 13 Jul 2023 10:20:32 +0000 |
| Subject: | note 128729 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220688@lists.php.net to get a copy of this message | ||
This wrapper prevents empty entries to appear in the final implosion.
function implode_no_empty( $separator = "", $array = [] )
{
foreach( $array AS $K => $STR )
if ( empty( $STR ) ) unset( $array[$K] );
return implode( $separator, $array );
}
$a = [ "a", "b", "c", "", "e" ];
$IMPL = implode_no_empty( "-", $a ); //result is a-b-c-e, not a-b-c--e
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.159.168 (proxied: 151.45.191.168)
----
Manual Page -- https://php.net/manual/en/function.implode.php
Edit -- https://main.php.net/note/edit/128729
Del: integrated -- https://main.php.net/note/delete/128729/integrated
Del: useless -- https://main.php.net/note/delete/128729/useless
Del: bad code -- https://main.php.net/note/delete/128729/bad+code
Del: spam -- https://main.php.net/note/delete/128729/spam
Del: non-english -- https://main.php.net/note/delete/128729/non-english
Del: in docs -- https://main.php.net/note/delete/128729/in+docs
Del: other reasons-- https://main.php.net/note/delete/128729
Reject -- https://main.php.net/note/reject/128729
Search -- https://main.php.net/manage/user-notes.php