This document provides an introduction to PHP programming. It covers PHP syntax, comments, variables, data types, operators, and conditional statements. The key points covered include:
- PHP code is placed between <?php ?> tags, files use the .php extension, and statements end with semicolons.
- Variables start with $ and are case-sensitive. Data types include strings, integers, floats, booleans, arrays, objects and NULL.
- Operators perform operations on variables and values, including arithmetic, assignment, comparison, increment/decrement, logical, string and array operators.
- Conditional statements like if statements allow executing code conditionally.
Dream Tech Labs offers C/C++ language training in Jalandhar, India. C was originally developed in the 1960s-1970s and is a general-purpose programming language. C++ was developed in the 1980s as an object-oriented successor to C that added classes, inheritance and other features. C++ provides stronger type checking, user-defined operators and functions, and code reuse through classes compared to C. Dream Tech Labs teaches both C and C++ programming.
The document provides an overview of basic C++ concepts including:
- C++ was developed as an extension of the C language and can be coded in an object-oriented or C-style.
- Keywords were added to support object-orientation, exceptions, and other features.
- Pointers in C++ store the address of a variable in memory.
- Blocks allow code sections to have their own local variables with minimized scope.
- Binding refers to converting functions/variables to machine addresses, which can be static/early or dynamic/late.
- Variables are statically scoped in C++ and type checking is done at compile-time rather than run-time.
- Most C++
This document contains information about pushdown automata (PDA) and examples of using PDA to represent certain formal languages. It provides examples of drawing PDA for languages of strings over an alphabet where the number of as equals the number of bs and for strings that represent legal arithmetic expressions over an alphabet of integer, operators and parentheses. Links to external resources on the topic are also included.
This document discusses using structures in C programming to store student records. It defines a student structure with roll number, name, and marks members. A program is provided that uses a structure array to store records for 10 students, reading input and then displaying the stored information. The key aspects of defining structures, declaring structure variables, accessing structure members, and allocating structure memory are explained. Sample problems are given to practice using structures to store book information and add distances.
This document contains notes from a lecture on C programming. It introduces basic C concepts like data types, operators, input/output functions, and provides examples of simple C programs. It also discusses compiling and executing C code, precedence rules for operators, and homework problems involving increment operators. The lecture aims to recap basic C knowledge and provide more in-depth coverage of topics like data types, arithmetic operations, and I/O functions.
structured programming Introduction to c fundamentalsOMWOMA JACKSON
This document provides an overview of structured programming and programming languages. It discusses the evolution from machine language to assembly language to high-level languages. It defines structured programming as enforcing logical structure and using basic constructs like sequence, selection, and iteration. The document then discusses programming languages in detail, including examples in BASIC and Pascal. It also covers the programming development process, explaining tools like pseudocode, flowcharts, and structure charts for planning solutions before coding.
Formalizing homogeneous language embeddingsClarkTony
This document discusses formalizing homogeneous language embeddings using a mu-calculus model. It proposes a model for embedding one language into another using evaluation, loading, and unloading functions. It provides examples of embedding a language into itself using fixed point operators, and using let bindings to embed one language into another. Further work is needed on parsing, static analysis, logics for combining languages, and practical considerations.
Dream Tech Labs offers C/C++ language training in Jalandhar, India. C was originally developed in the 1960s-1970s and is a general-purpose programming language. C++ was developed in the 1980s as an object-oriented successor to C that added classes, inheritance and other features. C++ provides stronger type checking, user-defined operators and functions, and code reuse through classes compared to C. Dream Tech Labs teaches both C and C++ programming.
The document provides an overview of basic C++ concepts including:
- C++ was developed as an extension of the C language and can be coded in an object-oriented or C-style.
- Keywords were added to support object-orientation, exceptions, and other features.
- Pointers in C++ store the address of a variable in memory.
- Blocks allow code sections to have their own local variables with minimized scope.
- Binding refers to converting functions/variables to machine addresses, which can be static/early or dynamic/late.
- Variables are statically scoped in C++ and type checking is done at compile-time rather than run-time.
- Most C++
This document contains information about pushdown automata (PDA) and examples of using PDA to represent certain formal languages. It provides examples of drawing PDA for languages of strings over an alphabet where the number of as equals the number of bs and for strings that represent legal arithmetic expressions over an alphabet of integer, operators and parentheses. Links to external resources on the topic are also included.
This document discusses using structures in C programming to store student records. It defines a student structure with roll number, name, and marks members. A program is provided that uses a structure array to store records for 10 students, reading input and then displaying the stored information. The key aspects of defining structures, declaring structure variables, accessing structure members, and allocating structure memory are explained. Sample problems are given to practice using structures to store book information and add distances.
This document contains notes from a lecture on C programming. It introduces basic C concepts like data types, operators, input/output functions, and provides examples of simple C programs. It also discusses compiling and executing C code, precedence rules for operators, and homework problems involving increment operators. The lecture aims to recap basic C knowledge and provide more in-depth coverage of topics like data types, arithmetic operations, and I/O functions.
structured programming Introduction to c fundamentalsOMWOMA JACKSON
This document provides an overview of structured programming and programming languages. It discusses the evolution from machine language to assembly language to high-level languages. It defines structured programming as enforcing logical structure and using basic constructs like sequence, selection, and iteration. The document then discusses programming languages in detail, including examples in BASIC and Pascal. It also covers the programming development process, explaining tools like pseudocode, flowcharts, and structure charts for planning solutions before coding.
Formalizing homogeneous language embeddingsClarkTony
This document discusses formalizing homogeneous language embeddings using a mu-calculus model. It proposes a model for embedding one language into another using evaluation, loading, and unloading functions. It provides examples of embedding a language into itself using fixed point operators, and using let bindings to embed one language into another. Further work is needed on parsing, static analysis, logics for combining languages, and practical considerations.
This document provides an introduction and overview for a course on programming using C++. The course assumes no prior programming experience. It will cover common C++ syntax, functions, classes, pointers, references, and object-oriented design. The course consists of 10 lectures covering various C++ topics. By the end of the course, students should have a working knowledge of C++ and be able to write their own functions and classes. While not comprehensive, the course aims to provide students with a solid foundation in C++.
The document contains 40 multiple choice questions related to computer science class 12. It covers topics like variables, data types, operators, loops, functions, arrays and more. The questions test concepts like escape sequences, format specifiers, assignment operators, comments, input/output functions, and the difference between various loops in C programming language. It is a practice test to help students prepare for their computer science exam.
The document provides an overview of topics that will be covered in a C programming course across 10 sessions. Session 1 introduces basic C concepts. Session 2 covers data types and variables. Session 3 discusses various operators in C like arithmetic, assignment, unary, conditional, relational and logical operators. Later sessions will cover loops, arrays, functions, structures, pointers, file I/O and more advanced C topics. The document includes examples of basic C programs to demonstrate concepts like input/output, arithmetic operations and unary operators.
This document discusses structured programming and arrays. It begins by introducing arrays as a way to store multiple values in a structured manner using indices, rather than individual variables. It then discusses how to input and output values from arrays using loops. It also covers multidimensional arrays and declaring arrays. The document provides examples of using arrays to store and manipulate data, such as finding averages and min/max values. It concludes by introducing bubble sort as a way to sort arrays into order.
The document provides an introduction to the basics of C++, including a brief history of C and C++, comparing C and C++, and providing a simple C++ "Hello World" program example. C++ was created by Bjarne Stroustrup in 1979 as an enhancement to the C language by adding object-oriented programming capabilities while still maintaining efficiency and flexibility. The document outlines some key differences between C and C++, such as C++ supporting object-oriented programming, classes, and templates while maintaining similar performance to C.
C++ is a general-purpose programming language created by Bjarne Stroustrup in 1979. It has imperative, object-oriented and generic programming features. The structure of a C++ program includes preprocessor directives, a main() function, and a program body. Variables are declared with a data type and used to store and manipulate data. C++ supports various operators for arithmetic, relational, logical, and bitwise operations.
This document discusses an integer overflow bug that can occur when calculating the midpoint or average of two integers in binary search and merge sort algorithms in Java. Specifically, the line of code "int mid = (low + high) / 2" can overflow for large values of low and high. The document proposes two solutions to avoid this overflow: 1) Using the unsigned right shift operator ">>" to calculate the midpoint as "int mid = (low + high) >> 1", and 2) Using the bitwise operators "AND" and "XOR" to calculate the average as "(i & j) + (i ^ j) / 2". It also briefly mentions another solution seen in classic C programming books of using subtraction instead
The document compares and contrasts the C and C++ programming languages. It notes that C was initially developed as a procedural language focused on algorithms and mathematics, while C++ was developed as an object-oriented extension of C focused on modeling real-world problems. It provides examples of simple programs in each language and describes some key differences, such as C++ supporting features like classes, inheritance, function overloading, and encapsulation that provide object-oriented capabilities not present in C. The document also defines some basic concepts of object-oriented programming.
C and C++ are programming languages with many similarities but some key differences. They both use basic built-in data types and control structures. However, C++ supports object-oriented programming features like classes, data hiding, and inheritance that are not present in C. C++ also supports function overloading, namespaces, and references, which provide more flexibility than C at the cost of additional complexity. Overall, C++ can be seen as an enhancement of C with additional high-level programming capabilities.
Polymorphism refers to the ability of an entity to take on multiple forms. There are two main types: static polymorphism and dynamic polymorphism. Static polymorphism involves binding functions at compile-time based on argument types, while dynamic polymorphism delays binding until runtime using virtual functions. Examples of static polymorphism include function overloading and operator overloading. Dynamic polymorphism allows subclasses to override virtual functions from the base class, and the correct version will be called based on the actual object type at runtime.
The document discusses HTML forms and handling form data with PHP. It explains how to use the GET and POST methods to send form data to PHP, and how to access submitted form values using $_GET and $_POST superglobals in PHP. It provides examples of handling different form elements like text fields, checkboxes, radio buttons, and select boxes. It also demonstrates how to validate required fields and display error messages.
This document discusses algorithms, flowcharts, pseudocode, and data types in programming. It defines an algorithm as a step-by-step procedure to solve problems. Pseudocode uses natural language to describe an algorithm, while a flowchart provides a graphical representation. The document also discusses using flowcharts and pseudocode in the planning process, and defines common data types like integer, string, boolean and their uses in programming.
The document provides information about connecting to a MySQL database from PHP. It discusses how to open a connection, perform queries, insert, select, update and delete data. Code examples are given to demonstrate how to connect to a MySQL database, create tables, insert and retrieve data using PHP functions like mysqli_connect(), mysqli_query(), and mysqli_fetch_assoc(). The document aims to explain the basic MySQL operations that can be performed after connecting to a database from a PHP application.
5th in the AskTOM Office Hours series on graph database technologies. https://devgym.oracle.com/pls/apex/dg/office_hours/3084
PGQL: A Query Language for Graphs
Learn how to query graphs using PGQL, an expressive and intuitive graph query language that's a lot like SQL. With PGQL, it's easy to get going writing graph analysis queries to the database in a very short time. Albert and Oskar show what you can do with PGQL, and how to write and execute PGQL code.
The sole purpose of sharing these slides are to educate the beginners of IT and Computer Science/Engineering. Credits should go to the referred material and also CICRA campus, Colombo 4, Sri Lanka where I taught these in 2017.
Efficient Context-sensitive Output Escaping for Javascript Template Enginesadonatwork
1) The document proposes a method called "context-aware output escaping" to defend against XSS attacks in JavaScript template engines. It uses contextual analysis of the template and applies appropriate filtering rules.
2) It presents an architecture that parses templates to build an AST, then uses context parsers like HTML, CSS, and URI parsers to analyze output contexts. Context-sensitive XSS filters are applied based on the analysis.
3) Key aspects of the design include the template parser and walker, handling of branching logic and sub-templates, and dealing with ambiguous contexts. Contextual parsing of HTML is also discussed.
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Roel Hartman
This document summarizes the development of a real-world logistic application using Oracle Application Express (APEX) for a client. It describes enhancing the existing application by replacing forms with APEX, including adding direct validation, replacing the calendar with jQuery, showing descriptions for codes, and improving the list of values functionality. The presentation provides examples of implementing these enhancements in APEX.
XQuery - The GSD (Getting Stuff Done) languagejimfuller2009
One of the hidden gems of the XML technology milieu is XQuery ... even if XML is not your thing (for example you work only with JSON) I will show you how XQuery is especially adept and super fast in terms of pure web development. And if you do happen to have a lot of XML I will also demonstrate how this concise, small data orientated language can result in serious productivity gains over other programming languages. XQuery is available today on the server, in the browser (mobile devices) and large deployments in both commercial and open source environments.
This talk will present both anecdotal and evidence based analysis showing how using XQuery can result in quicker development times over other programming languages when applied to the right scenarios and will try to help give a starting point to those wishing to investigate this extremely powerful little language.
Slides for a presentation on advanced PHP (object-orientation, frameworks, security and debugging) given for the CS25010 web development module at Aberystwyth University.
The document discusses machine learning workflows using REST APIs and client-side bindings. It describes how ML tasks like training, predicting, and evaluating models can be implemented as RESTful services. Direct HTTP requests allow basic automation but become complex for rich workflows. Client libraries provide more flexibility but are language-specific. The Bigmler tool offers a declarative way to implement common workflows with a simple command-line interface, hiding complexity while enabling reuse and scaling. Overall, the document examines different approaches for building ML systems and automating workflows using REST APIs at different levels of abstraction.
This presentation is part of training session delivered during Train The Trainer (TOT) program on Embedded Software Engineer job role supported by ESSCI.
This document provides an introduction and overview for a course on programming using C++. The course assumes no prior programming experience. It will cover common C++ syntax, functions, classes, pointers, references, and object-oriented design. The course consists of 10 lectures covering various C++ topics. By the end of the course, students should have a working knowledge of C++ and be able to write their own functions and classes. While not comprehensive, the course aims to provide students with a solid foundation in C++.
The document contains 40 multiple choice questions related to computer science class 12. It covers topics like variables, data types, operators, loops, functions, arrays and more. The questions test concepts like escape sequences, format specifiers, assignment operators, comments, input/output functions, and the difference between various loops in C programming language. It is a practice test to help students prepare for their computer science exam.
The document provides an overview of topics that will be covered in a C programming course across 10 sessions. Session 1 introduces basic C concepts. Session 2 covers data types and variables. Session 3 discusses various operators in C like arithmetic, assignment, unary, conditional, relational and logical operators. Later sessions will cover loops, arrays, functions, structures, pointers, file I/O and more advanced C topics. The document includes examples of basic C programs to demonstrate concepts like input/output, arithmetic operations and unary operators.
This document discusses structured programming and arrays. It begins by introducing arrays as a way to store multiple values in a structured manner using indices, rather than individual variables. It then discusses how to input and output values from arrays using loops. It also covers multidimensional arrays and declaring arrays. The document provides examples of using arrays to store and manipulate data, such as finding averages and min/max values. It concludes by introducing bubble sort as a way to sort arrays into order.
The document provides an introduction to the basics of C++, including a brief history of C and C++, comparing C and C++, and providing a simple C++ "Hello World" program example. C++ was created by Bjarne Stroustrup in 1979 as an enhancement to the C language by adding object-oriented programming capabilities while still maintaining efficiency and flexibility. The document outlines some key differences between C and C++, such as C++ supporting object-oriented programming, classes, and templates while maintaining similar performance to C.
C++ is a general-purpose programming language created by Bjarne Stroustrup in 1979. It has imperative, object-oriented and generic programming features. The structure of a C++ program includes preprocessor directives, a main() function, and a program body. Variables are declared with a data type and used to store and manipulate data. C++ supports various operators for arithmetic, relational, logical, and bitwise operations.
This document discusses an integer overflow bug that can occur when calculating the midpoint or average of two integers in binary search and merge sort algorithms in Java. Specifically, the line of code "int mid = (low + high) / 2" can overflow for large values of low and high. The document proposes two solutions to avoid this overflow: 1) Using the unsigned right shift operator ">>" to calculate the midpoint as "int mid = (low + high) >> 1", and 2) Using the bitwise operators "AND" and "XOR" to calculate the average as "(i & j) + (i ^ j) / 2". It also briefly mentions another solution seen in classic C programming books of using subtraction instead
The document compares and contrasts the C and C++ programming languages. It notes that C was initially developed as a procedural language focused on algorithms and mathematics, while C++ was developed as an object-oriented extension of C focused on modeling real-world problems. It provides examples of simple programs in each language and describes some key differences, such as C++ supporting features like classes, inheritance, function overloading, and encapsulation that provide object-oriented capabilities not present in C. The document also defines some basic concepts of object-oriented programming.
C and C++ are programming languages with many similarities but some key differences. They both use basic built-in data types and control structures. However, C++ supports object-oriented programming features like classes, data hiding, and inheritance that are not present in C. C++ also supports function overloading, namespaces, and references, which provide more flexibility than C at the cost of additional complexity. Overall, C++ can be seen as an enhancement of C with additional high-level programming capabilities.
Polymorphism refers to the ability of an entity to take on multiple forms. There are two main types: static polymorphism and dynamic polymorphism. Static polymorphism involves binding functions at compile-time based on argument types, while dynamic polymorphism delays binding until runtime using virtual functions. Examples of static polymorphism include function overloading and operator overloading. Dynamic polymorphism allows subclasses to override virtual functions from the base class, and the correct version will be called based on the actual object type at runtime.
The document discusses HTML forms and handling form data with PHP. It explains how to use the GET and POST methods to send form data to PHP, and how to access submitted form values using $_GET and $_POST superglobals in PHP. It provides examples of handling different form elements like text fields, checkboxes, radio buttons, and select boxes. It also demonstrates how to validate required fields and display error messages.
This document discusses algorithms, flowcharts, pseudocode, and data types in programming. It defines an algorithm as a step-by-step procedure to solve problems. Pseudocode uses natural language to describe an algorithm, while a flowchart provides a graphical representation. The document also discusses using flowcharts and pseudocode in the planning process, and defines common data types like integer, string, boolean and their uses in programming.
The document provides information about connecting to a MySQL database from PHP. It discusses how to open a connection, perform queries, insert, select, update and delete data. Code examples are given to demonstrate how to connect to a MySQL database, create tables, insert and retrieve data using PHP functions like mysqli_connect(), mysqli_query(), and mysqli_fetch_assoc(). The document aims to explain the basic MySQL operations that can be performed after connecting to a database from a PHP application.
5th in the AskTOM Office Hours series on graph database technologies. https://devgym.oracle.com/pls/apex/dg/office_hours/3084
PGQL: A Query Language for Graphs
Learn how to query graphs using PGQL, an expressive and intuitive graph query language that's a lot like SQL. With PGQL, it's easy to get going writing graph analysis queries to the database in a very short time. Albert and Oskar show what you can do with PGQL, and how to write and execute PGQL code.
The sole purpose of sharing these slides are to educate the beginners of IT and Computer Science/Engineering. Credits should go to the referred material and also CICRA campus, Colombo 4, Sri Lanka where I taught these in 2017.
Efficient Context-sensitive Output Escaping for Javascript Template Enginesadonatwork
1) The document proposes a method called "context-aware output escaping" to defend against XSS attacks in JavaScript template engines. It uses contextual analysis of the template and applies appropriate filtering rules.
2) It presents an architecture that parses templates to build an AST, then uses context parsers like HTML, CSS, and URI parsers to analyze output contexts. Context-sensitive XSS filters are applied based on the analysis.
3) Key aspects of the design include the template parser and walker, handling of branching logic and sub-templates, and dealing with ambiguous contexts. Contextual parsing of HTML is also discussed.
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Roel Hartman
This document summarizes the development of a real-world logistic application using Oracle Application Express (APEX) for a client. It describes enhancing the existing application by replacing forms with APEX, including adding direct validation, replacing the calendar with jQuery, showing descriptions for codes, and improving the list of values functionality. The presentation provides examples of implementing these enhancements in APEX.
XQuery - The GSD (Getting Stuff Done) languagejimfuller2009
One of the hidden gems of the XML technology milieu is XQuery ... even if XML is not your thing (for example you work only with JSON) I will show you how XQuery is especially adept and super fast in terms of pure web development. And if you do happen to have a lot of XML I will also demonstrate how this concise, small data orientated language can result in serious productivity gains over other programming languages. XQuery is available today on the server, in the browser (mobile devices) and large deployments in both commercial and open source environments.
This talk will present both anecdotal and evidence based analysis showing how using XQuery can result in quicker development times over other programming languages when applied to the right scenarios and will try to help give a starting point to those wishing to investigate this extremely powerful little language.
Slides for a presentation on advanced PHP (object-orientation, frameworks, security and debugging) given for the CS25010 web development module at Aberystwyth University.
The document discusses machine learning workflows using REST APIs and client-side bindings. It describes how ML tasks like training, predicting, and evaluating models can be implemented as RESTful services. Direct HTTP requests allow basic automation but become complex for rich workflows. Client libraries provide more flexibility but are language-specific. The Bigmler tool offers a declarative way to implement common workflows with a simple command-line interface, hiding complexity while enabling reuse and scaling. Overall, the document examines different approaches for building ML systems and automating workflows using REST APIs at different levels of abstraction.
This presentation is part of training session delivered during Train The Trainer (TOT) program on Embedded Software Engineer job role supported by ESSCI.
This document provides an overview of Hivemall, an open-source machine learning library built as a collection of Hive UDFs (user-defined functions). It can be used for scalable machine learning on large datasets using SQL queries. The document discusses Hivemall's supported algorithms, features, and industry use cases. It also provides examples of how to use Hivemall for tasks like classification, recommendation, and anomaly detection directly from SQL.
This document discusses using Apache Spark for big data analytics at an insurance pricing and customer analytics company called Earnix. It summarizes Earnix's business problems modeling large customer behavior data, how Spark helps address performance issues with their existing 10GB datasets, and improvements made to Spark's MLlib machine learning library. These include adding statistical functionality like covariance estimation to logistic regression models and optimizing algorithms to run efficiently on Spark. Benchmark results show Spark providing scalability by reducing algorithm run times as more nodes are added.
The document provides an overview of several C++ concepts including basic syntax, compiling programs, argument passing, dynamic memory allocation, and object-oriented programming. It demonstrates simple C++ programs and functions. It discusses best practices like separating interface and implementation using header files. It also introduces C++ standard library features like vectors and the importance of avoiding unnecessary copying.
Flowex - Railway Flow-Based Programming with Elixir GenStage.Anton Mishchuk
Flowex is a set of abstractions build on top Elixir GenStage which allows writing program with Flow-Based Programming paradigm.
I would say it is a mix of FBP and so-called Railway Oriented Programming (ROP) approach.
Flowex DSL allows you to easily create "pipelines" of Elixir GenStages.
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukElixir Club
This document discusses flow-based programming (FBP) and how it can be implemented using Elixir and the Flowex library. FBP defines applications as networks of independent processes that exchange data via message passing. Railway-oriented programming (ROP) is a design pattern that structures programs as a sequence of functions that pass data along. Railway FBP combines these concepts by implementing each function as an independent process. The Flowex library allows defining Elixir modules as processing pipelines and running them concurrently using GenStage to enable parallelism. It provides an easy way to build reusable and independently running process components.
The document provides an overview of JavaScript topics covered in an introductory course, including:
- Writing simple JavaScript programs using input/output, arithmetic operators, and decision-making statements
- Using JavaScript to make web pages more dynamic and interactive by producing immediate responses without server contact
- Three categories of JavaScript objects: native, host, and user-defined objects
- Two approaches for client-side scripting: inline and embedded <script> tags
- Collecting user input using the window prompt method and displaying output using document.write
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adderMalik Tauqir Hasan
The document discusses various topics related to Verilog including:
1. Port connection rules in Verilog modules can connect signals by ordered list or by name. Width matching between modules is allowed but may generate warnings.
2. Gate delays in Verilog allow specification of rise, fall, and turn-off delays for logic gates. Minimum, typical, and maximum delay values can also be provided.
3. Data flow modeling in Verilog describes a circuit in terms of data flow between registers rather than individual gates. This level of abstraction is known as register transfer level (RTL) modeling.
Homework 5
due Wednesday, March 8, 5pm
Submit zipped .m files on Canvas and printed published file in 182 George St box #15 or #16
You are encouraged to work with other students on this assignment but you are expected to write
and work on your own answers. You don’t need to provide the name of students you worked with.
You can find information about usage and syntax of any built-in Matlab function by typing
help xfunctionnamey
This document discusses JavaScript scripting language. It provides examples of simple JavaScript programs to print text on a web page using methods like writeLn and alert. It also demonstrates how to prompt users for input and perform basic arithmetic operations on the input. Key concepts covered include variables, data types, operators, and conditional statements.
The document discusses various networking components and devices, including their purposes and functions. It covers hubs, switches, routers, network interface cards, wireless access points, and firewalls. Hubs broadcast data to all ports, while switches only send to the destination port. Routers interconnect network segments and examine packet addresses to determine the best transmission path. Network interface cards allow computers to connect to networks, and wireless access points enable wireless devices to connect to wired networks. Firewalls control access between networks to protect data and resources.
This document provides an introduction to basic network concepts. It defines a computer network and its components, which include two or more interconnected computers, cables, network interface cards, switches, and operating systems. It describes the applications and benefits of networks, such as sharing resources and communicating over long distances, as well as some disadvantages like high installation costs. It also classifies networks based on their geographical area into personal, local, metropolitan and wide area networks. Finally, it discusses peer-to-peer and client-server network models.
This document provides an overview of cookies and sessions in PHP web programming. It defines cookies as small text files stored on a user's computer that can be used to identify users across browsing sessions. The key functions for working with cookies - setcookie(), $_COOKIE, and setcookie() with an expired time - are described. Sessions in PHP allow storing and accessing user data across multiple pages and are an alternative to cookies for maintaining state. The session handling functions - session_start(), $_SESSION, session_unset(), and session_destroy() - are explained.
This document provides an introduction to web development, covering topics such as client-server relationships, web languages and technologies, the internet and world wide web, internet protocols, domain name systems, hypertext transport protocol, and internet media types. The instructor hopes students will understand client-server relationships, that web pages have content, styling, and behavior, and that making web pages can be fun.
Language Localisation of Tamil using Statistical Machine Translation - ICTer2015Achchuthan Yogarajah
1) The document discusses using statistical machine translation to localize Tamil language content. It describes preparing a parallel corpus, building language models, aligning words, decoding translations, and evaluating the results using BLEU and human scoring.
2) The results show that output quality is better when training data is from a specific technical domain rather than generic data. Language models using 3-grams performed most efficiently.
3) Challenges included lack of enough technical training data and variations in translations due to usage differences, but statistical machine translation is suitable for language localization.
1) The document describes a Paddy Cultivation Management System created by a group of students to help farmers and improve the paddy cultivation process.
2) The system has separate interfaces for farmers and administrators. Farmers can view paddy information, prices, sell their crops, and check account balances. Administrators can manage crop data, approve sales, and view stock levels.
3) The goal of the system is to make paddy cultivation easier for farmers and help connect them to customers through a computerized process. It aims to improve lives and help develop the rice industry.
Machine Translation is an emerging field of Computer Science. Researchers have been done to make Machine Translation systems for different language pairs using different practices including rule based machine translation and Statistical Machine Translation (SMT). The goal of the project is to design a Statistical Machine translator for software language localization using Moses decoder. The system is expected to automatically localize (translate) software contents from English into Tamil by using Statistical Machine Translation.
The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the count of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most useful items.
http://java90.blogspot.com/2012/02/knapsack-problem-in-java.html
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPRAHUL
This Dissertation explores the particular circumstances of Mirzapur, a region located in the
core of India. Mirzapur, with its varied terrains and abundant biodiversity, offers an optimal
environment for investigating the changes in vegetation cover dynamics. Our study utilizes
advanced technologies such as GIS (Geographic Information Systems) and Remote sensing to
analyze the transformations that have taken place over the course of a decade.
The complex relationship between human activities and the environment has been the focus
of extensive research and worry. As the global community grapples with swift urbanization,
population expansion, and economic progress, the effects on natural ecosystems are becoming
more evident. A crucial element of this impact is the alteration of vegetation cover, which plays a
significant role in maintaining the ecological equilibrium of our planet.Land serves as the foundation for all human activities and provides the necessary materials for
these activities. As the most crucial natural resource, its utilization by humans results in different
'Land uses,' which are determined by both human activities and the physical characteristics of the
land.
The utilization of land is impacted by human needs and environmental factors. In countries
like India, rapid population growth and the emphasis on extensive resource exploitation can lead
to significant land degradation, adversely affecting the region's land cover.
Therefore, human intervention has significantly influenced land use patterns over many
centuries, evolving its structure over time and space. In the present era, these changes have
accelerated due to factors such as agriculture and urbanization. Information regarding land use and
cover is essential for various planning and management tasks related to the Earth's surface,
providing crucial environmental data for scientific, resource management, policy purposes, and
diverse human activities.
Accurate understanding of land use and cover is imperative for the development planning
of any area. Consequently, a wide range of professionals, including earth system scientists, land
and water managers, and urban planners, are interested in obtaining data on land use and cover
changes, conversion trends, and other related patterns. The spatial dimensions of land use and
cover support policymakers and scientists in making well-informed decisions, as alterations in
these patterns indicate shifts in economic and social conditions. Monitoring such changes with the
help of Advanced technologies like Remote Sensing and Geographic Information Systems is
crucial for coordinated efforts across different administrative levels. Advanced technologies like
Remote Sensing and Geographic Information Systems
9
Changes in vegetation cover refer to variations in the distribution, composition, and overall
structure of plant communities across different temporal and spatial scales. These changes can
occur natural.
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
Walmart Business+ and Spark Good for Nonprofits.pdfTechSoup
"Learn about all the ways Walmart supports nonprofit organizations.
You will hear from Liz Willett, the Head of Nonprofits, and hear about what Walmart is doing to help nonprofits, including Walmart Business and Spark Good. Walmart Business+ is a new offer for nonprofits that offers discounts and also streamlines nonprofits order and expense tracking, saving time and money.
The webinar may also give some examples on how nonprofits can best leverage Walmart Business+.
The event will cover the following::
Walmart Business + (https://business.walmart.com/plus) is a new shopping experience for nonprofits, schools, and local business customers that connects an exclusive online shopping experience to stores. Benefits include free delivery and shipping, a 'Spend Analytics” feature, special discounts, deals and tax-exempt shopping.
Special TechSoup offer for a free 180 days membership, and up to $150 in discounts on eligible orders.
Spark Good (walmart.com/sparkgood) is a charitable platform that enables nonprofits to receive donations directly from customers and associates.
Answers about how you can do more with Walmart!"
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
Strategies for Effective Upskilling is a presentation by Chinwendu Peace in a Your Skill Boost Masterclass organisation by the Excellence Foundation for South Sudan on 08th and 09th June 2024 from 1 PM to 3 PM on each day.
How to Setup Warehouse & Location in Odoo 17 InventoryCeline George
In this slide, we'll explore how to set up warehouses and locations in Odoo 17 Inventory. This will help us manage our stock effectively, track inventory levels, and streamline warehouse operations.
1. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
National Diploma in Information and Communication Technology
PHP :1-INTRODUCTION>
K72C001M07 - Web Programming
23 November 2018 K72C001M07 - Web Programming / Introduction 1
Y. Achchuthan
achchuthan@slgti.com
2. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Syntax
A PHP script starts with <?php and ends with ?>:
<?php
// PHP code goes here
?>
The default file extension for PHP files is ".php".
Note: PHP statements end with a semicolon (;)
23 November 2018 K72C001M07 - Web Programming / Introduction 2
3. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Comments
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
// You can also use comments to leave out parts of a
code line
$x = 5 /* + 15 */ + 5;
23 November 2018 K72C001M07 - Web Programming / Introduction 3
4. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Case Sensitivity
In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and
user-defined functions are NOT case-sensitive.
ECHO "Hello World!<br>"; //Hello World!
echo "Hello World!<br>"; //Hello World!
EcHo "Hello World!<br>"; //Hello World!
Variable names are case-sensitive.
$color = "red";
echo "My car is " . $color . "<br>"; //My car is red
echo "My house is " . $COLOR . "<br>"; //My house is
echo "My boat is " . $coLOR . "<br>"; //My boat is
23 November 2018 K72C001M07 - Web Programming / Introduction 4
5. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Declaring Variables
A variable starts with the $ sign, followed by the name of the variable:
$txt = "Hello world!"; //Hello world!
$x = 5; // 5
$y = 10.5; //10.5
23 November 2018 K72C001M07 - Web Programming / Introduction 5
6. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Rules for variables
• A variable starts with the $ sign, followed by the name of the variable
• A variable name must start with a letter or the underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive ($age and $AGE are two different
variables)
Note: Remember that PHP variable names are case-sensitive!
23 November 2018 K72C001M07 - Web Programming / Introduction 6
7. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Output Variables
<?php
$txt = "W3Schools.com";
echo "I love $txt!"; // I love W3Schools.com!
$txt = "W3Schools.com";
echo "I love " . $txt . "!"; // I love
W3Schools.com!
$x = 5;
$y = 4;
echo $x + $y; //9
?>
23 November 2018 K72C001M07 - Web Programming / Introduction 7
8. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Exercise
• Write a PHP program to display
• your name ,
• address,
• birthday
• and school
23 November 2018 K72C001M07 - Web Programming / Introduction 8
9. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Data Types
PHP supports the following data types:
• String
• Integer
• Float (floating point numbers - also called double)
• Boolean
• Array
• Object
• NULL
• Resource
23 November 2018 K72C001M07 - Web Programming / Introduction 9
10. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Data Types: String
A string can be any text inside quotes. You can use single or double
quotes
$x = "Hello world!";
$y = 'Hello world!';
echo $x;
echo "<br>";
echo $y;
23 November 2018 K72C001M07 - Web Programming / Introduction 10
11. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Data Types: Integer
An integer data type is a non-decimal number between -2,147,483,648
and 2,147,483,647.
Rules for integers:
• An integer must have at least one digit
• An integer must not have a decimal point
• An integer can be either positive or negative
• Integers can be specified in three formats: decimal (10-based), hexadecimal
(16-based - prefixed with 0x) or octal (8-based - prefixed with 0)
$x = 5985;
var_dump($x);
23 November 2018 K72C001M07 - Web Programming / Introduction 11
12. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Data Types: Float and Boolean
A float (floating point number) is a number with a decimal point or a
number in exponential form.
$x = 10.365;
A Boolean represents two possible states: TRUE or FALSE.
$x = true;
$y = false;
23 November 2018 K72C001M07 - Web Programming / Introduction 12
13. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Data Types: Array and NULL Value
An array stores multiple values in one single variable.
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
Null is a special data type which can have only one value: NULL.
$x = "Hello world!";
$x = null;
var_dump($x);
23 November 2018 K72C001M07 - Web Programming / Introduction 13
14. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Data Types: Object
An object is a data type which stores data and information on how to
process that data.
class Car {
function Car() {
$this->model = "VW";
}
}
// create an object
$herbie = new Car();
// show object properties
echo $herbie->model;
23 November 2018 K72C001M07 - Web Programming / Introduction 14
15. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
String Functions
Get The Length of a String
echo strlen("Hello world!"); // 12
Count The Number of Words in a String
echo str_word_count("Hello world!"); // 2
Reverse a String
echo strrev("Hello world!"); // !dlrow olleH
Search For a Specific Text Within a String
echo strpos("Hello world!", "world"); // 6
Replace Text Within a String
echo str_replace("world", "Dolly", "Hello world!"); // Hello Dolly!
23 November 2018 K72C001M07 - Web Programming / Introduction 15
16. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Constants
A constant is an identifier (name) for a simple value. The value cannot be
changed during the script.
define(name, value, case-insensitive)
• name: Specifies the name of the constant
• value: Specifies the value of the constant
• case-insensitive: Specifies whether the constant name should be case-insensitive. Default is
false
define("GREETING", "Welcome to slgti.com!");
echo GREETING; //Welcome to slgti.com!
define("GREETING", "Welcome to slgti.com!", true);
echo greeting; //Welcome to slgti.com!
define("PI",22/7);
echo 2*PI*7;
Note: Constants are automatically global and can be used across the entire
script.
23 November 2018 K72C001M07 - Web Programming / Introduction 16
17. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Operators
Operators are used to perform operations on variables and values.
PHP divides the operators in the following groups:
• Arithmetic operators
• Assignment operators
• Comparison operators
• Increment/Decrement operators
• Logical operators
• String operators
• Array operators
23 November 2018 K72C001M07 - Web Programming / Introduction 17
18. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Arithmetic Operators
The PHP arithmetic operators are used with numeric values to perform
common arithmetical operations, such as addition, subtraction,
multiplication etc.
Operator Name Example Result
+ Addition $x + $y Sum of $x and $y
- Subtraction $x - $y Difference of $x and $y
* Multiplication $x * $y Product of $x and $y
/ Division $x / $y Quotient of $x and $y
% Modulus $x % $y Remainder of $x divided by $
** Exponentiation $x ** $y $x to the $yth power
23 November 2018 K72C001M07 - Web Programming / Introduction 18
19. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example : Arithmetic Operators
$x = 10;
$y = 6;
echo $x + $y; //16
echo $x - $y; //4
echo $x * $y; //60
echo $x / $y; //1.6666666666667
echo $x % $y; //4
echo $x ** $y; //1000000
23 November 2018 K72C001M07 - Web Programming / Introduction 19
20. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Assignment Operators
The PHP assignment operators are used with numeric values to write a
value to a variable.
The basic assignment operator in PHP is "=". It means that the left
operand gets set to the value of the assignment expression on the
right.
Assignment Same as... Description
x = y x = y The left operand gets set to the
value of the expression on the right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus
23 November 2018 K72C001M07 - Web Programming / Introduction 20
21. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Assignment Operators
$x = 20;
$x += 100;
echo $x; //120
$x -= 30;
echo $x; //90
$y = 6;
echo $x * $y; //540
$x /= 5;
echo $x; //18
$x %= 4;
echo $x; //2
23 November 2018 K72C001M07 - Web Programming / Introduction 21
22. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Comparison Operators
The PHP comparison operators are used to compare two values
(number or string):
23 November 2018 K72C001M07 - Web Programming / Introduction 22
Operator Name Example Result
== Equal $x == $y Returns true if $x is equal to $y
=== Identical $x === $y Returns true if $x is equal to $y, and they are of the
same type
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
!== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not
of the same type
> Greater than $x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
>= Greater than or
equal to
$x >= $y Returns true if $x is greater than or equal to $y
<= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y
23. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Comparison Operators
$x = 100;
$y = "100";
var_dump($x==$y); //boolean true
var_dump($x===$y); //boolean false
var_dump($x!=$y); //boolean false
var_dump($x<>$y); //boolean false
var_dump($x!==$y); //boolean true
$y = 50;
var_dump($x > $y); //boolean true
var_dump($x < $y); //boolean false
var_dump($x >= $y); //boolean true
var_dump($x <= $y); //boolean false
23 November 2018 K72C001M07 - Web Programming / Introduction 23
24. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Increment / Decrement Operators
The PHP increment operators are used to increment a variable's value.
The PHP decrement operators are used to decrement a variable's
value.
23 November 2018 K72C001M07 - Web Programming / Introduction 24
Operator Name Description
++$x Pre-increment Increments $x by one, then returns $x
$x++ Post-increment Returns $x, then increments $x by one
--$x Pre-decrement Decrements $x by one, then returns $x
$x-- Post-decrement Returns $x, then decrements $x by one
25. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Increment Operators
$x = 10;
echo ++$x; //11
echo $x++; //11
echo $x; //12
echo --$x; //11
echo $x--; //11
23 November 2018 K72C001M07 - Web Programming / Introduction 25
26. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Logical Operators
The PHP logical operators are used to combine conditional statements.
23 November 2018 K72C001M07 - Web Programming / Introduction 26
Operator Name Example Result
and And $x and $y True if both $x and $y are true
or Or $x or $y True if either $x or $y is true
xor Xor $x xor $y True if either $x or $y is true, but
not both
&& And $x && $y True if both $x and $y are true
|| Or $x || $y True if either $x or $y is true
! Not !$x True if $x is not true
27. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Logical Operators
$x = 100;
$y = 50;
if ($x == 100 and $y == 50) {
echo "Hello world!";
} // Hello world!
if ($x == 100 xor $y == 80) {
echo "Hello world!";
} // Hello world!
if ($x == 100 || $y == 50) {
echo "Hello world!";
} // Hello world!
23 November 2018 K72C001M07 - Web Programming / Introduction 27
28. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
String Operators
PHP has two operators that are specially designed for strings.
• Example:
$txt1 = "Hello";
$txt2 = " world!";
echo $txt1 . $txt2; //Hello world!
$txt1 .= $txt2;
echo $txt1; //Hello world!
23 November 2018 K72C001M07 - Web Programming / Introduction 28
Operator Name Example Result
. Concatenation $txt1 . $txt2 Concatenation of $txt1 and
$txt2
.= Concatenation
assignment
$txt1 .= $txt2 Appends $txt2 to $txt1
29. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Array Operators
The PHP array operators are used to compare arrays.
23 November 2018 K72C001M07 - Web Programming / Introduction 29
Operator Name Example Result
+ Union $x + $y Union of $x and $y
== Equality $x == $y Returns true if $x and $y have the same
key/value pairs
=== Identity $x === $y Returns true if $x and $y have the same
key/value pairs in the same order and
of the same types
!= Inequality $x != $y Returns true if $x is not equal to $y
<> Inequality $x <> $y Returns true if $x is not equal to $y
!== Non-identity $x !== $y Returns true if $x is not identical to $y
30. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Array Operators
$x = array("a" => "red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
print_r ($x + $y);
// Array ( [a] => red [b] => green [c] => blue [d] => yellow )
var_dump($x == $y); // boolean false
var_dump($x === $y); // boolean false
23 November 2018 K72C001M07 - Web Programming / Introduction 30
31. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Conditional Statements
• if statement - executes some code if one condition is true
• if...else statement - executes some code if a condition is true and
another code if that condition is false
• if...elseif....else statement - executes different codes for more than
two conditions
• switch statement - selects one of many blocks of code to be executed
Syntax
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if this condition is true;
} else {
code to be executed if all conditions are false;
}
23 November 2018 K72C001M07 - Web Programming / Introduction 31
32. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Conditional Statement
$a = 10;
$b = 20;
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
23 November 2018 K72C001M07 - Web Programming / Introduction 32
33. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Exercise: Conditional Statements
Write a program to show discount according to number of
books.(Number of books =15)
– 10<=books<=20 Discount-15%
– 20<books<=30 Discount-20%
– books>30 Discount-30%
23 November 2018 K72C001M07 - Web Programming / Introduction 33
34. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
switch Statement
Use the switch statement to select one of many blocks of code to be executed.
• Syntax
switch (n) {
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
...
default:
code to be executed if n is different
from all labels;
}
23 November 2018 K72C001M07 - Web Programming / Introduction 34
35. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: switch Statement
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue
or green!";
}
23 November 2018 K72C001M07 - Web Programming / Introduction 35
36. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Exercise: switch Statement
• Write PHP code for finding the number of days in a month.
• Write PHP code for display the day when give as short name of day.
(ex Mon -> Monday)
23 November 2018 K72C001M07 - Web Programming / Introduction 36
37. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Loops
Often when you write code, you want the same block of code to run
over and over again in a row. Instead of adding several almost equal
code-lines in a script, we can use loops to perform a task like this.
In PHP, we have the following looping statements:
• While- loops through a block of code as long as the specified
condition is true
• do...while - loops through a block of code once, and then repeats the
loop as long as the specified condition is true
• for - loops through a block of code a specified number of times
• foreach - loops through a block of code for each element in an array
23 November 2018 K72C001M07 - Web Programming / Introduction 37
38. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
while Loop
The while loop executes a block of code as long as the specified
condition is true.
• Syntax
while (condition is true) {
code to be executed;
}
• Example:
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
23 November 2018 K72C001M07 - Web Programming / Introduction 38
39. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
for Loop
The for loop is used when you know in advance how many times the
script should run.
• Syntax
for (initeger counter; test counter; increment
counter) {
code to be executed;
}
• Example:
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
23 November 2018 K72C001M07 - Web Programming / Introduction 39
40. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
foreach Loop
The foreach loop works only on arrays, and is used to loop through
each key/value pair in an array.
• Syntax
foreach ($array as $value) {
code to be executed;
}
• Example:
$colors = array("red", "green", "blue",
"yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
23 November 2018 K72C001M07 - Web Programming / Introduction 40
41. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Functions
Besides the built-in PHP functions, we can create our own functions.
• A function is a block of statements that can be used repeatedly in a
program.
• A function will not execute immediately when a page loads.
• A function will be executed by a call to the function.
• Syntax
function functionName() {
code to be executed;
}
Note: A function name can start with a letter or underscore (not a
number), Function names are NOT case-sensitive.
Tip: Give the function a name that reflects what the function does!
23 November 2018 K72C001M07 - Web Programming / Introduction 41
42. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
User Defined Function
function writeMsg() {
echo "Hello world!";
}
writeMsg(); // call the function
• we create a function named "writeMsg()".
• The opening curly brace ( { ) indicates the beginning of the function
code and the closing curly brace ( } ) indicates the end of the
function.
• The function outputs "Hello world!".
• To call the function, just write its name
23 November 2018 K72C001M07 - Web Programming / Introduction 42
43. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Function Arguments
function familyName1($fname) {
echo "$fname Refsnes.<br>";
}
familyName1("Jani");
familyName1("Hege");
function familyName2($fname, $year) {
echo "$fname Refsnes. Born in $year <br>";
}
familyName2("Hege", "1975");
familyName2("Stale", "1978");
23 November 2018 K72C001M07 - Web Programming / Introduction 43
44. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Function Default Arguments
function setHeight($minheight = 50) {
echo "The height is : $minheight <br>";
}
setHeight(350);
setHeight(); // will use the default value of 50
setHeight(135);
setHeight(80);
23 November 2018 K72C001M07 - Web Programming / Introduction 44
45. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Function returning values
function sum($x, $y) {
$z = $x + $y;
return $z;
}
echo "5 + 10 = " . sum(5, 10) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "2 + 4 = " . sum(2, 4);
23 November 2018 K72C001M07 - Web Programming / Introduction 45
46. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Exercise
• Write a function for +,-,* and / of two numbers and return values.
• Write separate functions for +,-,* and / of two numbers and return
values.
• Addition
• Subtraction
• Division
• Multiplication
• Modulus
23 November 2018 K72C001M07 - Web Programming / Introduction 46
47. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Built in Function: getdate()
Returns an associative array of information related to the timestamp. The
returning array contains ten elements with relevant information needed
when formatting a date string
• Example
$today = getdate();
print_r($today);
/* Array (
[seconds] => 40
[minutes] => 58
[hours] => 21
[mday] => 17
[wday] => 2
[mon] => 6
[year] => 2003
[yday] => 167
[weekday] => Tuesday
[month] => June
[0] => 1055901520
) */23 November 2018 K72C001M07 - Web Programming / Introduction 47
48. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Array
• What is an Array?
• An array is a special variable, which can hold more than one value at a time.
• Example
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and "
. $cars[2] . ".";
• Types of arrays
• Indexed arrays: Arrays with a numeric index
• Associative arrays: Arrays with named keys
• Multidimensional arrays: Arrays containing one or more arrays
23 November 2018 K72C001M07 - Web Programming / Introduction 48
49. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Indexed Arrays
There are two ways to create indexed arrays
• The index can be assigned automatically (index always starts at 0),
like this:
$cars = array("Volvo", "BMW", "Toyota");
• Index can be assigned manually:
$cars[0] = "Volvo";
$cars[1] = "BMW";
$cars[2] = "Toyota";
23 November 2018 K72C001M07 - Web Programming / Introduction 49
50. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Indexed Arrays
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and "
. $cars[2] . ".";
//Get The Length of an Array
echo count($cars);
//Loop Through an Indexed Array
$arrlength = count($cars);
for($x = 0; $x < $arrlength; $x++) {
echo $cars[$x];
echo "<br>";
}
23 November 2018 K72C001M07 - Web Programming / Introduction 50
51. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Associative Arrays
Associative arrays are arrays that use named keys that you assign to
them.
• There are two ways to create an associative array:
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
• Assigned manually:
$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43";
23 November 2018 K72C001M07 - Web Programming / Introduction 51
52. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Associative Arrays
$age = array("Peter"=>"35", "Ben"=>"37",
"Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years
old.";
//Loop Through an Associative Array
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
23 November 2018 K72C001M07 - Web Programming / Introduction 52
53. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Example: Associative Arrays
//Loop Through an Associative Array
$students = array(
"name“ => "Saman",
"address“ => "Kandy Rd, Malabe",
"tp“ => “(+94) 812 56789",
"email“ => "saman@slgti.com"
);
foreach($students as $key=>$value) {
echo "$key = $value","<BR>";
}
23 November 2018 K72C001M07 - Web Programming / Introduction 53
54. Sri Lanka-German Training InstituteDepartment of Information and Communication Technology
Reference
www.w3schools.com
www.php.net
23 November 2018 K72C001M07 - Web Programming / Introduction 54