PHP Developer Question:
Download Questions PDF

How To get access a specific character in a String using PHP?

Answer:

Any character in a string can be accessed by a special string element expression:
► $string{index} - The index is the position of the character counted from left and starting from 0.

Here is a PHP script example:
<?php
$string = 'It's Friday!';
echo "The first character is $string{0} ";
echo "The first character is {$string{0}} ";
?>

This script will print:
The first character is It's Friday!{0}
The first character is I

Download PHP Developer Interview Questions And Answers PDF

Previous QuestionNext Question
How many ways to include the array elements in Double-Quoted Strings using PHP?How you can assign a new character in a String using PHP?