Complete the code to get the length of the string.
<?php $string = "hello"; $length = [1]($string); echo $length; ?>
The strlen function returns the length of a string in PHP.
Complete the code to count how many times 'a' appears in the string.
<?php $string = "banana"; $count = substr_count($string, [1]); echo $count; ?>
The substr_count function counts how many times a substring appears in a string. Here, we count 'a'.
Fix the error in the code to correctly get the string length.
<?php $text = "apple"; $len = [1]($text); echo $len; ?>
Use strlen to get the length of a string in PHP. count is for arrays.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
<?php $words = ["cat", "house", "dog", "elephant"]; $lengths = []; foreach ($words as $word) { if ([1]($word) [2] 3) { $lengths[$word] = strlen($word); } } print_r($lengths); ?>
Use strlen to get the length of each word and check if it is greater than 3.
Fill all three blanks to create an associative array with uppercase keys and their original values for words longer than 4 characters.
<?php $words = ["apple", "bat", "carrot", "dog"]; $result = []; foreach ($words as $word) { if (strlen($word) [1] 4) { $result[[2]] = [3]; } } print_r($result); ?>
Check if the word length is greater than 4, then use the uppercase word as the key and the original word as the value.