-
Notifications
You must be signed in to change notification settings - Fork 0
StringList
Michael Tils edited this page Mar 25, 2015
·
1 revision
The StringList is a class to simply build a string of separated parts. It extends the OrderedList so you can use all method of it.
use Collection\StringList;
$cssClasses = new StringList(['header','important','annotation']);
echo $cssClasses;
// prints 'header important annotation'
echo $cssClasses->append('inline');
// prints 'header important annotation inline'
echo $cssClasses->remove('important');
// prints 'header annotation inline'You can also pass or assign a delimiter to split the "words"
use Collection\StringList;
$fruits = new StringList(['apple','orange','banana'], ', ');
echo $fruits;
// prints 'apple, orange, banana'StringList also allows to set a prefix and a suffix
use Collection\StringList;
$fruits = new StringList(['id','name','email'], ', ');
$fruits->prefix = 'SELECT ';
$fruits->suffix = ' FROM users';
echo $fruits;
// prints 'SELECT id, name, email FROM users'You could also use it as a string
use Collection\StringList;
$greeting = new StringList(['h','e','l','l','o'], '');
echo $greeting;
// prints 'hello'
echo $greeting->pop(0)->insert(0,'b');
// prints 'bello'use Collection\StringList;
$greeting = StringList::fromString('id,name,email', ',');
// Result: StringList['id','name','email']