Professional Documents
Culture Documents
Content outline:
2.1. Creating and Manipulating Array
2.2. Extracting data from arrays
2.3. Traversing arrays
2.4. Function and its types
2.5. Operations on String and String functions
2.6. Basic Graphics Concepts
- explode()
- This is built in function of PHP.
- The explode function breaks a string into an array.
- This function splits a string based on delimeter.
- Syntax:
- array explode(separator, original_string, no_of_elements)
- The explode function accepts 3 parameters.
- First two parameters i.e separator and original_string are compulsory and no_of_elements
is optional.
- Separator: this character specifies at which point to split the string.
- original_string: this is input string which is to be split in array.
- no_of_elements: it is used to specify the number of elements of the array. Value of this
parameter can be positive, negative or zero.
- Positive value(N) – if the number of elements after separating with respect to the separator
emerges to be greater than this value the first N-1 elements remain same and the last
element is the whole remaining string.
- Negative value (N) - if negative value is passes as parameter then first N elements of the
array will trimmed out and remaining part of the string shall be returned as a array.
- Zero – if this parameter is zero then the array returned will have only one element i.e whole
string.
- Example:
- <html>
- <body>
- <?php
$str = “Hello, welcome to the world of fun”;
$a=explode(“ “, $str);
1) array_flip():
- This function is exchanges key with their associated values.
- This is built in function of PHP.
- Syntax : array_flip(array)
- Example:
<?php
$a = array(“first”=>”Rahul”, “second”=>”Sham”,”third”=>”Riya”);
echo “Array before flip”;
print_r($a);
$res = array_flip($a);
echo “Array after flip”;
print_r($res);
?>
2) Traversing array
3) Modifying data in arrays
4) Deleting array elements
5) Array values
6) Sorting arrays
7) Splitting and merging arrays
String functions:
<html>
//echo()
echo "Welcome to world of fun";
print "<br>";
//
$str = "Hello Hello Students.........";
echo $str . "<br>";
echo ltrim($str,"Hello");
print "<br>";
//
print "Hello world!";
print "<br>";
//
$number = 99;
$str = "Sakshi";
printf("SSC percentage of %s - %u",$str,$number);
print "<br>";
//
$str = "Hello Students";
echo $str . "<br>";
echo rtrim($str,"Students");
print "<br>";
//
echo str_repeat("Hello",6);
print "<br>";
//space is considered.
print_r(str_split("Hello Welcome"));
//
echo str_word_count("Hello Students. Welcome to the world of fun.");
print "<br>";
//
echo strcasecmp("Hello World!","HELLO WORLD!");
print "<br>";
//
echo "--";
echo strchr("Hello world!","world");
print "<br>";
//
echo "--";
echo strcmp("Hello world!","Hello world!");
print "<br>";
//
echo strlen("Hello");
print "<br>";
//
echo stripos("I am Final year student of computer engg","Final");
print "<br>";
//
echo stristr("Hello world!","WORLD");
print "<br>";
//
echo strpos("I love php, I love php too!","php");
//
echo strrev("Welcome to GGSP");
print "<br>";
//
echo strrpos("I am student of computer engg of GGSP ","of");
print "<br>";
//
$str = "Hello Students!";
echo $str . "<br>";
echo trim($str,"Hel");
print "<br>";
//
echo ucfirst("hello world!");
print "<br>";
//
echo ucwords("hello world");
print "<br>";
//
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n");
?>
</body>
</html>