Home / PHP / TechO2 Hyderabad Web Developer Interview Questions

TechO2 Hyderabad Web Developer Interview Questions

After done with the technical round, they conduct a system test over skype. here is a question they asked over the conversation, I resolved them, you can find the solution as well. if you think you have the best solution than this don’t forget to write in the comment section.

TechO2 Hyderabad Web Developer Interview Questions

1)$fruits = [ “apple”,”banana”,”mango”];
$quantity = [10,5,12];
Output: $fruitswithQuantity = [ “apple” => 10, “banana” => 5, “mango” => 12]

Answer:

<?php 
$fruits = ['apple','banana','mango']; 
$quantity = [10,5,12]; 
$result = array_combine ($fruits,$quantity); 
print_r($result); 
?>

2) $number = [1,2,3]; Output : $number = [9,4,1]

Answer:

<?php 
$number = [1,2,3]; 
foreach ($number as $value) { 
$output[] = $value * $value; 
} 
$ot = array_reverse($output); 
$str = implode (", ", $ot);
 echo $str; 
?>

3) Sum of given string?  $string = “1,2,3,4,5,6,9”; Output: 30

Answer:

<?php 
$string = '1,2,3,4,5,6,9'; 
$res = explode(',',$string); 
$result = 0; 
foreach($res as $row) { 
$result += $row; 
} echo "Total :". $result; 
?>

4) $string = “This is sample string”; Output: “string_sample_is_This”;

Answer:

<?php
$str = "This is sample string";
$spaceCount = substr_count($str, " ");
$letterIndx = 0;
for($i=0; $i<=$spaceCount; $i++) {
 $spaceIndx = strpos($str, " ", $letterIndx); 
if ($spaceIndx == 0) {
 $word = substr($str, $letterIndx);
 } else { 
$word = substr($str, $letterIndx, $spaceIndx - $letterIndx);
 } 
$myArray[] = $word;
 $letterIndx = $spaceIndx + 1; 
}
 $reverse = array_reverse($myArray); 
foreach($reverse as $rev) { 
$rev." "; 
}
 echo str_replace(" ","_",$$rev); ?>

About Mohammad Fareed

Software Engineer @ Tekzenit.

Check Also

How to use Internationalization in Codeigniter

How to use Internationalization in Codeigniter In Language File Create your Label language\english\message_lang.php $lang[‘greet’] = …

Leave a Reply

Your email address will not be published. Required fields are marked *