Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
typo3
qfq
Commits
2b8cd878
Commit
2b8cd878
authored
Jan 20, 2016
by
Carsten Rose
Browse files
OnArray.php: new function trimArray()
parent
663a25ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
qfq/helper/OnArray.php
View file @
2b8cd878
...
...
@@ -48,4 +48,19 @@ class OnArray {
return
;
}
/**
* Trim all elemements in an array.
* The array has to be a 1-dimensional array.
*
* @param array $arr
* @param string $character_mask
* @return array
*/
public
static
function
trimArray
(
array
$arr
,
$character_mask
)
{
foreach
(
$arr
as
$key
=>
$item
)
{
$arr
[
$key
]
=
trim
(
$item
,
$character_mask
);
}
return
$arr
;
}
}
\ No newline at end of file
tests/phpunit/OnArrayTest.php
View file @
2b8cd878
...
...
@@ -38,4 +38,11 @@ class OnArrayTest extends \PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
array
(),
$expected
);
}
public
function
testTrimArray
()
{
$raw
=
[
'hello'
,
'"next"'
,
'"without trailing'
,
'without leading"'
,
' with whitespace '
,
'" with tick and whitespace "'
,
''
];
$expected
=
[
'hello'
,
'next'
,
'without trailing'
,
'without leading'
,
' with whitespace '
,
' with tick and whitespace '
,
''
];
$this
->
assertEquals
(
\
qfq\helper\OnArray
::
trimArray
(
$raw
,
'"'
),
$expected
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment