php - How do I return the variable from a function? -


i trying return variable function , print out. displaying unexpected t_string right now.... can help?

function reg_word($i){ $reg_word = "/[^a-za-z0-9 ]/"; $i = preg_replace($reg_word, '', $i); } $suggestion = function reg_word($_post['suggestions']); print_r($suggestion); 

function reg_word($i){ $reg_word = "/[^a-za-z0-9 ]/"; return preg_replace($reg_word, '', $i); } $suggestion = reg_word($_post['suggestions']); print_r($suggestion); 

you had function keyword before reg_word($_post['suggestions']); - don't need it. need use return keyword return function.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -