Answers for "select the first letter of each item in an array php"

PHP
1

php foreach first element

foreach($array as $key => $element) {
    if ($key === array_key_first($array))
        echo 'FIRST ELEMENT!';

    if ($key === array_key_last($array))
        echo 'LAST ELEMENT!';
}
Posted by: Guest on July-02-2021
0

php get first character of each word

if(!function_exists('get_avatar')){
    function get_avatar($str){
        $acronym;
        $word;
        $words = preg_split("/(\s|\-|\.)/", $str);
        foreach($words as $w) {
            $acronym .= substr($w,0,1);
        }
        $word = $word . $acronym ;
        return $word;
    }
}
Posted by: Guest on August-30-2021

Code answers related to "select the first letter of each item in an array php"

Browse Popular Code Answers by Language