PHP: If String[Index] is in Array, PHP: String from String[1] to String[last] -
is there php call in_str?
…something similar in_array..
am using if-else take each word (string) in array of strings (from form-input-text) see if start index [0] equal single character string in array..
also, how 1 @ string string[1] string[last]?
(these 2 questions highlighted in code using format: **code**)
if(isset($_post['radiobuttonname']) && $_post['radiobuttonname'] == 'avalue') { $stringsarray = array($_post['forminputtext']); $vowels = array("a", "e", "i", "o", "u", "a", "e", "i", "o", "u"); foreach ($stringsarray $stringsarraystring) { if (**in_str**($stringsarraystring[0], $vowels)) { echo $stringsarraystring . "aword" . "< >"; } else { echo "**$stringsarraystring[1] $stringsarraystring[last]**" . "$stringsarraystring[0]" . "aword" . "< >"; } } }
you can use strpos check if letter in string, search array you'll need use foreach...
foreach($vowels $vowel) { $firstletterisavowel = (strpos($stringsarraystring, $vowel) === 0 ? true : false); } if ($firstletterisavowel)) { echo $stringsarraystring . "aword" . "< >"; } else { echo "**".substr($stringsarraystring, 1) . "$stringsarraystring[0]" . "aword" . "< >"; } note use of === instead of == strpos returns false if not found, , 0 == false. did because question, i'd rather check if $stringarraystring[0] vowel this...
in_array ( $stringarraystring[0] , $vowels)
Comments
Post a Comment