Showing posts with label bhavik dutt. Show all posts
Showing posts with label bhavik dutt. Show all posts

Day -8 Bhavik PHP SWITCH CASE bhavikphp

This is example of switch Case:-


$test = 13;

switch ($test) {

case "15" :
echo "Lucky day of my life.";
break;

case "13" :
echo "Bhavik datt birthday.";
break;

default :
echo "I love PHP.";
break;

}

Output:- Bhavik datt birthday.

Day -7 Bhavik PHP String Function with example bhavikphp


STRING REPLACE
(I)
$bhavik = str_replace("college", "school", "I love my college");
Print $bhavik;
This is output: I love my school
(II)
$numbers = array("1", "2", "3");
$words = array("one", "two", "three");
$phrase = "I have only 1 girlfriend and 3 friends";
$bhavik = str_replace($numbers, $words, $phrase);
Print $bhavik;

This is output: I have only one girlfriend and three friends
...........................................................

STRING POSITION

echo strpos("Hello BHAVIK!","BHAVIK");

output:- 6
.........................................................................................

STRING LENGTH

echo strlen("Hello BHAVIK");

output:-12
............................................................

String To Lowercase

The strtolower() function converts a string to lowercase.

echo strtolower("Hello BHAVIK.");
output:-
hello bhavik.
............................................................

SUB STRING

The substr() function returns a part of a string.
substr(string,start,length)

echo substr("Hello BHAVIK!",6);

The output :BHAVIK
!
..............................................................

STRING WORD COUNT

If you want to find out the number of words in a string, you can use str_word_count():

$bhavik = 'bhavik, dutt!';
echo str_word_count( $bhavik );

Output:- "2"
................................................................

Day -6 Bhavik PHP Function (bhavikphp)


function writename()
{
echo 'bhavik datt';
}
echo 'my name is ';
writename();
...........................................................
Output:- my name is bhavik datt

In this example writename is function and we can use like this
For your Practice I give you more example

1. Practice All Function .... DOWNLOAD

2. Function with return value.. DOWNLOAD

3. Name2 Example.... DOWNLOAD

Day -4 FOR LOOP, WHILE LOOP and DO WHILE LOOP BHAVIK PHP

"WHILE LOOP"


php
$i=1;
while($i<=5)
{
echo '
'.$i;
$i++;
}
?>
In this example we see that
1. define
2. condition
3. increment. while loop syntax,

Now "DO WHILE LOOP"

php
$i=1;
do
{
$i++;
echo '
'.$i;
}
while($i<=5);
?>

In the do while loop
1. define
2.increment
3.condition

but we are mainly use while loop

Now "FOR LOOP"

$sum=0;
for($i=1;$i<=4;$i++)
{
$sum=$sum+$i;
echo '
'.$i;
}
echo '
'.'sum = '.$sum;
?>

Output:-
1
2
3
4
sum = 10

Code Review these example FOR LOOP, WHILE and DO WHILE

1. FACTORIAL..... DOWNLOAD

2. FIBONACCI ... DOWNLOAD

3. ROOT GIVE NUMBER... DOWNLOAD

4. 10-10 GAP... DOWNLOAD

5. INVERSE NUMBER..DOWNLOAD

6. ROOT SUM.. DOWNLOAD

7. SERIES 3 MINUS. DOWNLOAD

8. SERIES 3 AND 6 . DOWNLOAD



Day -3 Bhavik PHP Operators like Arithmetic Operators , Assignment Operators ,Comparison Operators , Logical Operators

Arithmetic operators

PHP features arithmetic operator

SymbolNameExampleResult
+additionecho 7 + 512
-subtractionecho 7 - 52
*multiplicationecho 7 * 535
/divisionecho 7 / 51.4
%modulusecho 7 % 52

Comparison operators

PHP's comparison operators compare 2 values, if the comparison succee producing a Boolean result of true, or false if it failed. you are use with if...else and while loop etc.
PHP comparison operators

SymbolNameUsageResult
==equal toa == btrue if a equals b, otherwise false
!=not equal toa != btrue if a does not equal b, otherwise false
===identical toa === btrue if a equals b and they are of the same type, otherwise false
!==not identical toa !== btrue if a does not equal b or they are not of the same type, otherwise false
<less thana < btrue if a is less than b, otherwise false
>greater thana > btrue if a is greater than b, otherwise false
<=less than or equal toa <= btrue if a is less than or equal to b, otherwise false
>=greater than or equal toa >= btrue if a is greater than or equal to b, otherwise false

Logical operators


PHP logical operators:

SymbolNameExampleResult
&&anda && btrue if a and b are true, otherwise false
andanda and btrue if a and b are true, otherwise false
||ora || btrue if a or b are true, otherwise false
orora or btrue if a or b are true, otherwise false
xorxora xor btrue if a or b — but not both — are true, otherwise false
!not!atrue if a is false; false if a is true

Assignment operators

$p=5;
$p+=1;
echo 'sum = '.$p;

$q=5;
$q-=1;
echo '
sub ='.$q;

$r=5;
$r*=5;
echo '
mult='.$r;

$s=5;
$s/=5;
echo '
div='.$s;
----------------------------------------------------
Output:-

sum = 6
sub =4
mult=25
div=1
************************************************
If you competed these all task so now you code review these example like Calculator,
value is odd than or even than,
value is positive or negative
so download these example and review of code...

1. Calculator...........

........Download

2. Value is odd or even than....

........Download

3. Value is positive or negative.....

........Download

Day -2 PHP Introduction and Variable, Strings concatenation

Introduction

What is PHP???

PHP: Hypertext Preprocessor (the name is a recursive acronym) is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. ...
------------------------------------------------------------------------
Now we are start PHP with Variable define....
alway start with $ sign

$variable_name = value;
$sum = 10;
-----------------------------------

String and String concatenation in PHP


:-In the concatenation we can use (.)
and any string is apply is "" or ''


$first='BhavikPHP';
echo $first;
$second='Datt';
echo "This is concat for two string:---".$second.$first;
?>


0utput

BhavikPHP
This is concat for two string:---DattBhavikPHP

Day -1 HTLM Tags learning and Form Design

Hi friends do you ready for learning PHP??
so we are start first step HML Tag and form design,
Student information form
**********************************************
----------------------------------------------------
Output:-

Download This HTML Code:- Download

BhavikPHP Date Function, date format php

Hi friends.......

Here i give you all format for Date function,
if you do not know for date function so download
this it is very esay file and use it..

Day-5 Bhavik PHP Array Functions(Array-Functions)

This all array function with example


Function



Explanation



Example



sizeof($arr)



This
function returns the number of elements in an array.



Use
this function to find out how many elements an array contains; this
information is most commonly used to initialize a loop counter when
processing the array.


Code:

$data = array("red", "green", "blue");



echo "Array has " . sizeof($data) . " elements";

?>



Output:

Array has 3 elements

array_values($arr)



This
function accepts a PHP array and returns a new array containing only its
values (not its keys). Its counterpart is the array_keys() function.



Use
this function to retrieve all the values from an associative array.


Code:

$data = array("hero" => "Holmes", "villain" => "Moriarty");
print_r(array_values($data));

?>



Output:

Array

(
[0] => Holmes
[1] => Moriarty

)

array_keys($arr)



This
function accepts a PHP array and returns a new array containing only its keys
(not its values). Its counterpart is the array_values() function.



Use
this function to retrieve all the keys from an associative array.


Code:

$data = array("hero" => "Holmes", "villain" => "Moriarty");
print_r(array_keys($data));

?>



Output:

Array

(
[0] => hero
[1] => villain

)

array_pop($arr)



This
function removes an element from the end of an array.


Code:

$data = array("Donald", "Jim", "Tom");
array_pop($data);
print_r($data);

?>



Output:

Array

(
[0] => Donald
[1] => Jim

)

array_push($arr, $val)



This
function adds an element to the end of an array.


Code:

$data = array("Donald", "Jim", "Tom");
array_push($data, "Harry");
print_r($data);

?>



Output:

Array

(
[0] => Donald
[1] => Jim
[2] => Tom
[3] => Harry

)

array_shift($arr)



This
function removes an element from the beginning of an array.


Code:

$data = array("Donald", "Jim", "Tom");
array_shift($data);
print_r($data);

?>



Output:

Array

(
[0] => Jim
[1] => Tom

)

array_unshift($arr, $val)



This
function adds an element to the beginning of an array.


Code:

$data = array("Donald", "Jim", "Tom");
array_unshift($data, "Sarah");
print_r($data);

?>



Output:

Array

(
[0] => Sarah
[1] => Donald
[2] => Jim
[3] => Tom

)

each($arr)



This
function is most often used to iteratively traverse an array. Each time each() is called,
it returns the current key-value pair and moves the array cursor forward one
element. This makes it most suitable for use in a loop.


Code:

$data = array("hero" => "Holmes", "villain" => "Moriarty");

while (list($key, $value) = each($data)) {
echo "$key: $value \n";

}

?>



Output:

hero: Holmes

villain: Moriarty

sort($arr)



This
function sorts the elements of an array in ascending order. String values
will be arranged in ascending alphabetical order.



Note: Other
sorting functions include
asort(), arsort(),
ksort(), krsort() and rsort()
.


Code:

$data = array("g", "t", "a", "s");

sort($data);
print_r($data);

?>



Output:

Array

(
[0] => a
[1] => g
[2] => s
[3] => t

)

array_flip($arr)



The
function exchanges the keys and values of a PHP associative array.



Use
this function if you have a tabular (rows and columns) structure in an array,
and you want to interchange the rows and columns.


Code:

$data = array("a" => "apple", "b" => "ball");
print_r(array_flip($data));

?>



Output:

Array

(
[apple] => a
[ball] => b

)

array_reverse($arr)



The
function reverses the order of elements in an array.



Use
this function to re-order a sorted list of values in reverse for easier
processing—for example, when you're trying to begin with the minimum or
maximum of a set of ordered values.


Code:

$data = array(10, 20, 25, 60);
print_r(array_reverse($data));

?>



Output:

Array

(
[0] => 60
[1] => 25
[2] => 20
[3] => 10

)

array_merge($arr)



This
function merges two or more arrays to create a single composite array. Key
collisions are resolved in favor of the latest entry.



Use
this function when you need to combine data from two or more arrays into a
single structure—for example, records from two different SQL queries.


Code:

$data1 = array("cat", "goat");

$data2 = array("dog", "cow");
print_r(array_merge($data1, $data2));

?>



Output:

Array

(
[0] => cat
[1] => goat
[2] => dog
[3] => cow

)

array_rand($arr)



This
function selects one or more random elements from an array.



Use
this function when you need to randomly select from a collection of discrete
values—for example, picking a random color from a list.


Code:

$data = array("white", "black", "red");

echo "Today's color is " . $data[array_rand($data)];

?>



Output:

Today's color is red

array_search($search,
$arr)



This
function searches the values in an array for a match to the search term, and
returns the corresponding key if found. If more than one match exists, the
key of the first matching value is returned.



Use
this function to scan a set of index-value pairs for matches, and return the
matching index.


Code:

$data = array("blue" => "#0000cc", "black" => "#000000", "green" => "#00ff00");

echo "Found " . array_search("#0000cc", $data);

?>



Output:

Found blue

array_slice($arr, $offset, $length)



This
function is useful to extract a subset of the elements of an array, as
another array. Extracting begins from array offset $offset and
continues until the array slice is $length elements long.



Use
this function to break a larger array into smaller ones—for example, when
segmenting an array by size ("chunking") or type of data.


Code:

$data = array("vanilla", "strawberry", "mango", "peaches");
print_r(array_slice($data, 1, 2));

?>



Output:

Array

(
[0] => strawberry
[1] => mango

)

array_unique($data)



This
function strips an array of duplicate values.



Use
this function when you need to remove non-unique elements from an array—for
example, when creating an array to hold values for a table's primary key.


Code:

$data = array(1,1,4,6,7,4);
print_r(array_unique($data));

?>



Output:

Array

(
[0] => 1
[3] => 6
[4] => 7
[5] => 4

)

array_walk($arr, $func)



This
function "walks" through an array, applying a user-defined function
to every element. It returns the changed array.



Use
this function if you need to perform custom processing on every element of an
array—for example, reducing a number series by 10%.


Code:

function reduceBy10(&$val, $key) {
$val -= $val * 0.1;

}



$data = array(10,20,30,40);
array_walk($data, 'reduceBy10');
print_r($data);

?>



Output:

Array

(
[0] => 9
[1] => 18
[2] => 27
[3] => 36

)


You also code review these program

1. Array Count.. DOWNLOAD

2. Array Key...
DOWNLOAD

3. Array Map...
DOWNLOAD

4. Array Print_r.
DOWNLOAD

5. Array Search..
DOWNLOAD

5. Array Value...
DOWNLOAD

6. Array Function.
DOWNLOAD

7. Combine Array.
DOWNLOAD

8. Array Exist...
DOWNLOAD

9. Array Sort...
DOWNLOAD

10.Array Ksort...
DOWNLOAD

PHP Interview Question Answers


  1. What does a special set of tags <?= and ?> do in PHP? - The output is displayed directly to the browser.

  2. What’s the difference between include and require? - It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

  3. I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem? - PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.


  4. Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example? - In this example it wouldn’t matter, since the variable is all by itself, but if you were to print something like "{$a},000,000 mln dollars", then you definitely need to use the braces.

  5. How do you define a constant? - Via define() directive, like define ("MYCONSTANT", 100);

  6. How do you pass a variable by value? - Just like in C++, put an ampersand in front of it, like $a = &$b

  7. Will comparison of string "10" and integer 11 work in PHP? - Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.

  8. When are you supposed to use endif to end the conditional statement? - When the original if was followed by : and then the code block without braces.

  9. Explain the ternary conditional operator in PHP? - Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.

  10. How do I find out the number of parameters passed into function? - func_num_args() function returns the number of parameters passed in.

  11. If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b? - 100, it’s a reference to existing variable.

  12. What’s the difference between accessing a class method via -> and via ::? - :: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.

  13. Are objects passed by value or by reference? - Everything is passed by value.

  14. How do you call a constructor for a parent class? - parent::constructor($value)

  15. What’s the special meaning of __sleep and __wakeup? - __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

  16. Why doesn’t the following code print the newline properly? <?php
    $str = ‘Hello, there.nHow are you?nThanks for visiting TechInterviews’;
    print $str;
    ?>
    Because inside the single quotes the n character is not interpreted as newline, just as a sequence of two characters - and n.

  17. Would you initialize your strings with single quotes or double quotes? - Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

  18. How come the code <?php print "Contents: $arr[1]"; ?> works, but <?php print "Contents: $arr[1][2]"; ?> doesn’t for two-dimensional array of mine? - Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would’ve worked.

  19. What is the difference between characters 23 and x23? - The first one is octal 23, the second is hex 23.

  20. With a heredoc syntax, do I get variable substitution inside the heredoc contents? - Yes.

  21. I want to combine two variables together:
     $var1 = 'Welcome to ';
    $var2 = 'TechInterviews.com';

    What will work faster? Code sample 1:


    $var 3 = $var1.$var2;

    Or code sample 2:


    $var3 = "$var1$var2";

    Both examples would provide the same result - $var3 equal to "Welcome to TechInterviews.com". However, Code Sample 1 will work significantly faster. Try it out with large sets of data (or via concatenating small sets a million times or so), and you will see that concatenation works significantly faster than variable substitution.


  22. For printing out strings, there are echo, print and printf. Explain the differences. - echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:
     <?php echo 'Welcome ', 'to', ' ', 'TechInterviews!'; ?>

    and it will output the string "Welcome to TechInterviews!" print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.


  23. I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP? - On large strings that need to be formatted according to some length specifications, use wordwrap() or chunk_split().

  24. What’s the output of the ucwords function in this example?
     $formatted = ucwords("TECHINTERVIEWS IS COLLECTION OF INTERVIEW QUESTIONS");
    print $formatted;

    What will be printed is TECHINTERVIEWS IS COLLECTION OF INTERVIEW QUESTIONS.

    ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first.



  25. What’s the difference between htmlentities() and htmlspecialchars()? - htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.

  26. What’s the difference between md5(), crc32() and sha1() crypto on PHP? - The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

  27. So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()? - Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.


Home