PHP String Functions Quiz

DistinguishedFern avatar
DistinguishedFern
·
·
Download

Start Quiz

Study Flashcards

10 Questions

Which function capitalizes the first character of a string?

ucfirst()

What is the purpose of the substr() function?

To return a portion of a string

Which function adds elements to the beginning of an array?

array_unshift()

If you need to check if a string is set, which function would you use?

isset()

Which function sorts an array in descending order?

rsort()

Which function would you use to remove the last element of an array?

array_pop()

What does the trim() function do?

Removes whitespace from the beginning and end of a string

Which function searches for a value in an array and returns its key?

array_search()

What does strtolower() do?

Converts all characters of a string to lowercase

Which of these functions will remove whitespace only from the beginning of a string?

ltrim()

Study Notes

String Functions

  • String manipulation:
    • strtolower(): converts a string to lowercase
    • strtoupper(): converts a string to uppercase
    • ucfirst(): capitalizes the first character of a string
    • lcfirst(): converts the first character of a string to lowercase
  • String extraction:
    • substr(): returns a portion of a string
    • substr_replace(): replaces a portion of a string
  • String searching:
    • strpos(): finds the position of a substring within a string
    • strrpos(): finds the position of a substring within a string, starting from the end
  • String verification:
    • empty(): checks if a string is empty
    • isset(): checks if a string is set
  • String formatting:
    • trim(): removes whitespace from the beginning and end of a string
    • ltrim(): removes whitespace from the beginning of a string
    • rtrim(): removes whitespace from the end of a string

Array Functions

  • Array creation:
    • array(): creates a new array
    • range(): creates an array of consecutive integers
  • Array manipulation:
    • array_push(): adds one or more elements to the end of an array
    • array_pop(): removes the last element of an array
    • array_shift(): removes the first element of an array
    • array_unshift(): adds one or more elements to the beginning of an array
  • Array searching:
    • in_array(): checks if a value exists in an array
    • array_search(): searches for a value in an array and returns its key
  • Array sorting:
    • sort(): sorts an array in ascending order
    • rsort(): sorts an array in descending order
    • asort(): sorts an array in ascending order, maintaining key associations
    • ksort(): sorts an array by key in ascending order
  • Array filtering:
    • array_filter(): filters elements of an array using a callback function
    • array_diff(): returns an array of elements that are not present in another array

String Functions

  • String manipulation:
    • strtolower() converts a string to lowercase
    • strtoupper() converts a string to uppercase
    • ucfirst() capitalizes the first character of a string
    • lcfirst() converts the first character of a string to lowercase
  • String extraction:
    • substr() returns a portion of a string
    • substr_replace() replaces a portion of a string
  • String searching:
    • strpos() finds the position of a substring within a string
    • strrpos() finds the position of a substring within a string, starting from the end
  • String verification:
    • empty() checks if a string is empty
    • isset() checks if a string is set
  • String formatting:
    • trim() removes whitespace from the beginning and end of a string
    • ltrim() removes whitespace from the beginning of a string
    • rtrim() removes whitespace from the end of a string

Array Functions

  • Array creation:
    • array() creates a new array
    • range() creates an array of consecutive integers
  • Array manipulation:
    • array_push() adds one or more elements to the end of an array
    • array_pop() removes the last element of an array
    • array_shift() removes the first element of an array
    • array_unshift() adds one or more elements to the beginning of an array
  • Array searching:
    • in_array() checks if a value exists in an array
    • array_search() searches for a value in an array and returns its key
  • Array sorting:
    • sort() sorts an array in ascending order
    • rsort() sorts an array in descending order
    • asort() sorts an array in ascending order, maintaining key associations
    • ksort() sorts an array by key in ascending order
  • Array filtering:
    • array_filter() filters elements of an array using a callback function
    • array_diff() returns an array of elements that are not present in another array

Test your knowledge of string manipulation and extraction functions in PHP, including strtolower, strtoupper, ucfirst, and more.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

PHP String Concatenation Quiz
8 questions

PHP String Concatenation Quiz

ResourcefulObsidian3288 avatar
ResourcefulObsidian3288
PHP Basics: Introduction and Syntax
12 questions
Web Development Lecture 9: PHP Loops and Functions
5 questions
PHP Web Development Lecture 10
5 questions
Use Quizgecko on...
Browser
Browser