Q:

Write a PHP program to check if a given string starts with 'C#' or not

0

Write a PHP program to check if a given string starts with 'C#' or not.

All Answers

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

<?php
function test($str) 
{
   return (strlen($str) < 3 && $str=="C#") || (substr($str,0,2) == "C#" && substr($str,2,1) == ' ');
}

var_dump(test("C# Sharp"));
var_dump(test("C#"));
var_dump(test("C++"));
Sample Output:
bool(true)
bool(true)
bool(false)

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