Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Initializing arrays
1. Introduction to PHP
Initializing Arrays
• No of ways to initialize the array.
– For e.g.
• $ncststaff[] = “amrish”;
$ncststaff[] = “murali”;
$ncststaff[] = “narayan”;
• $ncststaff[123] = “amrish”;
$ncststaff[122] = “murali”;
$ncststaff[121] = “narayan”;
• $ncststaff = array (“amrish”, “murali”, “narayan”);
– to change the indices of the array use => operator.
A. Chaubal 1
2. Introduction to PHP
Accessing the Array Elements
• The elements in the array can be accessed by
using the list and each constructs
– for e.g
while(list($key,$value) = each(countries))
echo(“$value<BR>n”);
– current(<arrayname>) gives the current value
being accessed. key(<arrayname>) gives the index
of the current element that is being accessed.
– prev(<arrayname>) gives the previous element.
– next(<arrayname>) gives the next element.
A. Chaubal 2
3. Introduction to PHP
Accessing the Array Elements (cont.)
– Array_walk(<arrayname>,<function_name>)
• function_name is the function that is written for every
member of an array.
• For e.g
$ncststaff = array (“amrish”, “murali”, “narayan”);
array_walk ($ncststaff, printstaff);
// function to print each element of the array
function printstaff($names) {
echo “<B>$names</B><BR>n”;
}
A. Chaubal 3
4. Introduction to PHP
Arrays (cont.)
• $ncststaff = array (“dake” => array(“amrish”, “lakshana”, “venkat”),
“spc” => array(“narayan”, “murali”,“prasad”));
– creates a two dimensional array.
• Sorting Functions
– sort() : sorts the elements in the numeric and
alphabetical order.
– rsort() : sorts the elements in the reverse order.
– asort() : sorts the elements in the array without
changing the indices.
– ksort() : sorts the arrays by key.
A. Chaubal 4
5. Introduction to PHP
Classes
• Class is a template of an object and includes
the properties and methods that describe an
object and behavior.
• Class in PHP is defined using class statement.
A. Chaubal 5
6. Introduction to PHP Classes (cont.)
• For e.g
<?
class company {
// define the properties
var $companyname;
// define the methods
function company($cname) {
$this->companyname = $cname;
}
function getnames($idcode) {
//return the name of the employee for the required idcode
}
}
?>
A. Chaubal 6
7. Introduction to PHP
PHP Richness
• PHP comes with myriad of options i.e.
supports several APIs and interfaces to other
programming tools such as
– Database connectivity.
– LDAP
– XML
– Mail protocols such as IMAP, SMTP
– Image functions
etc….
A. Chaubal 7
8. Introduction to PHP
Support for Regular Expressions
• Not pretty things to look at and work with.
– E.g. ^.+@.+..+$
• PHP takes over the headache from the
programmers for explicitly coding for pattern
matching.
• Functions:
– ereg() and eregi()
– ereg_replace() & eregi_replace()
– split()
A. Chaubal 8
9. Introduction to PHP
Image Generation & Manipulation
• PHP offers powerful set of functions for
generating and manipulating the images.
– Rendering regular geometric figures, modifying
images
– manipulate text, font and color and even the pixels
in the image.
• ….creating the images on the fly.
A. Chaubal 9
10. Introduction to PHP
Image Generation & Manipulation
(cont.)
• PHP uses the GD library for the most of the image
functionality that it offers.
• GD library is used for generating the two-dimensional
graphics.
• PHP API’s provides us with functions to:
– Create, delete, resize and modify images.
– Draw basic geometric figures
– Manipulate text and fonts
– Manipulate colors
– Interlace and manipulate pixels
– Handle PostScript files
A. Chaubal 10
11. Introduction to PHP
Mailing functions
• Sending E-Mails
– Mail()
• Used to send simple text messages.
• Depends on the local mail delivery system.
– Using SMTP
• Accepts the e-mail for every recipient and goes through trouble
of delivering the e-mails.
• Receiving E-Mails
– PHP works out well with the IMAP protocol.
– Rich set of support functions
• Imap_open, impa_delete, imap_close, imap_mail_copy,
imap_mail_move etc.
A. Chaubal 11
12. Introduction to PHP
PHP-Database Connectivity
• Supports APIs for accessing large number of
databases.
• ODBC is a standard API for accessing a
database that has PHP support.
A. Chaubal 12
13. Introduction to PHP
PHP-Database Connectivity
• Some of Oracle 8.x functions.
– OCILogon
– OCILogoff
– OCIParse
– OCIFetch; OCIFetchInto; OCIFetchStatement
– OCIExecute
– OCIFreeStatement
A. Chaubal 13
14. Introduction to PHP
LDAP Support in PHP
• PHP provides LDAP API’s that allows the
programmers to create LDAP clients; by
providing transparent access to backend LDAP
directory servers.
– For e.g.
• Web based e-mail client.
• Telephone Directory.
A. Chaubal 14
15. Introduction to PHP
XML Support in PHP
• PHP supports a set of functions that can be
used for writing PHP-based XML applications.
• These functions are used for parsing well
formed XML document.
A. Chaubal 15
16. Introduction to PHP
References
• Professional PHP programming
– By Jesus Castagnetto, Chris Schollo et al
• www.phpbuilder.com
• www.php.net
A. Chaubal 16