ListAppend is a rather simple utility function, however when you are dealing with lists, it can prove a great ally. This is a function that I pulled out of a class of list functions. I will publish the entire class once I get the individual functions published. The default delimiter for the ListAppend function is a ','. The delimiter length should be 1 character. Regardless of the size of the delimiter, the function will only use the first character.
|
The Function: |
<php
function ListAppend($list,$value,$delimiter= ",") { $delimiter = substr($delimiter,1); $nList = $list . $delimiter . $value; return $nList; }
?>
|
|
Usage: |
Statement | Output | Comment | ListAppend('elem1,elem2', '' ) | elem1,elem2, | Appended element is empty; delimiter is last character in list; list length is 2. | ListAppend('', 'elem1,elem2' ) | elem1,elem2 | List length is 2. | ListAppend("one___two", "three", "___") | "one___two_three" | Inserted the first character of delimiters before "three." |
|
|
ListAppend works great to add values to a list. This function will default to a ',' for a delimiter!
For Example:
<?php $list = "abcd"; $value = "Z"; echo ListAppend($list,$value); ?>
The results is 'abcd,Z'!
By sending the correct delimiter through, in this case '': <?php $list = "abcd"; $value = "Z" ; echo ListAppend($list,$value,""); ?>
The results is 'abcdZ'!
|