<!DOCTYPE html>
<html>
<body>
<?php
$x = 'adnan';
$$x = 'zaib';
echo $$x;
echo "</br>";
echo $adnan;
echo "</br>";
echo "what is is the use of &";
echo "</br>";
$a = '1';
$b = &$a;
echo $b;
echo "</br>";
$b = "2$b";
echo $a.','.$b; //21,21 q k b point kr rha ha as a reeferece variable to $a mtlb: $b jo ha wo $a variable ki memory ko point kr rha hai
echo "</br>";
$x = 5;
echo $x+++$x++; //11
echo "</br>";
echo "<br />";
echo $x---$x--; // 1
echo "<br />";
$array[10] = 'adnan';
print_r($array);
print($array[10]);
echo '</br> length: '. count($array);
echo '</br>';
$y = "man"; $$y = 100; echo $y; echo $$y; echo $man;
echo '</br>';
$text = 'adnan';
echo strlen($text);
echo '</br>';
$text[10] = 'zaib'; //array([10] => zaib)
print_r($text);
?>
</body>
</html>
1: What is the output of the following code:
$a = '1';
$b =
&$a;
$b =
"2$b";
echo
$a.", ".$b;
2: What will this code output and why?
$x = true
and false;
var_dump($x);
3: What will be the output of the code below?
$x = 5;
echo $x;
echo
"<br />";
echo
$x+++$x++;
echo
"<br />";
echo $x;
echo
"<br />";
echo
$x---$x--;
echo
"<br />";
echo $x;
4: Output of following code?
<?php $y = "man"; $$y = 100; echo $y;
echo $$y; echo $man; ?>
5: After the code below is executed, what will be
the value of $text and what will strlen($text) return? Explain your answer.
$text = 'John ';
$text[10] = 'Doe';
6: Loop Through Array :
$input_array = array("aaa", "b", "b",
"b","b","b", "b","b");
$output_array = array();
for ($i =
0; $i < count($input_array); $i++)
{
$temp
=
$input_array[!isset($input_array[$i-1]) ? $i : $i-1];
$input_array[!isset($input_array[$i-1]) ? $i : $i-1] =
$input_array[!isset($input_array[$i-1]) ? $i : $i];
$input_array[!isset($input_array[$i-1])
? $i : $i] = $temp;
array_push($output_array,$input_array);
}
print_r($output_array);
solution
Array ( [0] => Array ( [0] => aaa [1] => b [2] => b [3] => b [4] => b [5] => b [6] => b [7] => b ) [1] => Array ( [0] => b [1] => aaa [2] => b [3] => b [4] => b [5] => b [6] => b [7] => b ) [2] => Array ( [0] => b [1] => b [2] => aaa [3] => b [4] => b [5] => b [6] => b [7] => b ) [3] => Array ( [0] => b [1] => b [2] => b [3] => aaa [4] => b [5] => b [6] => b [7] => b ) [4] => Array ( [0] => b [1] => b [2] => b [3] => b [4] => aaa [5] => b [6] => b [7] => b ) [5] => Array ( [0] => b [1] => b [2] => b [3] => b [4] => b [5] => aaa [6] => b [7] => b ) [6] => Array ( [0] => b [1] => b [2] => b [3] => b [4] => b [5] => b [6] => aaa [7] => b ) [7] => Array ( [0] => b [1] => b [2] => b [3] => b [4] => b [5] => b [6] => b [7] => aaa ) )
7: Remove Colon ( : ) from
each date time exists in string.
$string = "Lorem Ipsum is simply
dummy text : 2022-07-19 12:12:56 Contrary to popular belief, Lorem Ipsum is not
simply random text: 2022-07-19 23:12:56 . There are many variations of passages
of Lorem Ipsum available, but the majority have suffered alteration in some
form 14:12:56".
New String should be:
$string = "Lorem Ipsum is simply dummy
text : 2022-07-19 12 12 56 Contrary to popular belief, Lorem Ipsum is not
simply random text: 2022-07-19 23 12 56 . There are many variations of passages
of Lorem Ipsum available, but the majority have suffered alteration in some
form 2022-07-19 14 12 56".
solution
$string = "Lorem Ipsum is simply dummy text : 2022-07-19 12:12:56 Contrary to popular belief, Lorem Ipsum is not simply random text: 2022-07-19 23:12:56 . There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form 14:12:56.";
// Define a regular expression pattern for detecting times
$pattern = '/\b(?:\d{2}:\d{2}:\d{2}|\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\b/';
// $pattern = '/\b\d{2}:\d{2}:\d{2}\b/';
preg_match_all($pattern,$string, $matches);
// print_r($matches);
foreach($matches[0] as $match){
$formatedString = str_replace(':','',$time);
$string = str_replace($time,$formatedString,$string);
}
echo $string;
8 : Write a mysql query to
remove duplicate cliente having unique telefono without creating new table.
Table name xtable. Remaining dataset
will
Dataset :
DROP TABLE IF EXISTS `xtable`;
CREATE TABLE `xtable` (
`cliente` varchar(255) DEFAULT NULL,
`telefono` varchar(255) DEFAULT NULL,
`telefono2` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT
CHARSET=utf8;
INSERT INTO `xtable`
(`cliente`, `telefono`, `telefono2`) VALUES
('lavaggio', '', NULL);
INSERT INTO `xtable`
(`cliente`, `telefono`, `telefono2`) VALUES
('cisco', '', '3333');
INSERT INTO `xtable`
(`cliente`, `telefono`, `telefono2`) VALUES
('ibm', '555', '');
INSERT INTO `xtable`
(`cliente`, `telefono`, `telefono2`) VALUES
('gsoftware', '4444', '6728'),
('gsoftware', '4444', ''),
('gsoftware', '', ''),
('gsoftware', '8320', ''),
('cisco', NULL, NULL),
('lavaggio', NULL, NULL),
('gsoftware', '4444', ''),
('ibm', '555', ''),
('gsoftware', '4444', '6728'),
('gsoftware', '', '4444');
Output:
Cliente telefono telefono2
lavaggio Empty NULL
cisco Empty 3333
ibm 555 Empty
gsoftware 4444 6728
gsoftware 8320 Empty
ace 1212 1212
Comments
Post a Comment