php - How do I create a function to add to existing information? -
i have existing code has string of words. need able create function add existing string of words. struggling how in php. new , have looked has gotten me nowhere.
when said , done, like:
a function add new word existing variable contains string of words. (below existing code of words)
$words = 'apple sauce, tasty chicken, new monkey, left right';
below can come with:
function newword($word){ $newalpha = 'time table'; if ($newalpha > 0){ echo $newalpha => $words; } }
i know that's not right i'm new php , mysql. may worth noting need function inserted database $words housed, bonus if me that.
just concatenate string:
function newword($word, $words){ if($word != ''){//or other check want return "$words, $word"; } return $words; }
usage:
$newalpha = 'time table'; $words = newword($newalpha,$words);//now $words has $newalpha appended onto end comma , space
you can see in action here:
http://sandbox.onlinephpfunctions.com/code/436189dc45208fb78bdfa4262772600559f29d44
Comments
Post a Comment