PHP Developer Question:
Download Job Interview Questions and Answers PDF
How you can assign a new character in a String using PHP?
Answer:
The string element expression, $string{index}, can also be used at the left side of an assignment statement. This allows you to assign a new character to any position in a string. Here is a PHP script example:
<?php
$string = 'It's Friday?';
echo "$string ";
$string{11} = '!';
echo "$string ";
?>
This script will print:
It's Friday?
It's Friday!
<?php
$string = 'It's Friday?';
echo "$string ";
$string{11} = '!';
echo "$string ";
?>
This script will print:
It's Friday?
It's Friday!
Download PHP Developer Interview Questions And Answers
PDF
Previous Question | Next Question |
How To get access a specific character in a String using PHP? | How To concatenate the two strings together in PHP? |