Q:

Write a PHP program to check whether the first two characters and last two characters of a given string are same

0

Write a PHP program to check whether the first two characters and last two characters of a given string are same

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function test($s1)
 { 
    return substr($s1, 0, 2) == substr($s1, strlen($s1) - 2, 2);
 }

var_dump(test("abab"));
var_dump(test("abcdef"));
var_dump(test("xyzsderxy"));

Sample Output:

bool(true)
bool(false)
bool(true)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now