Page 127 - Open Soource Technologies 304.indd
P. 127

Open Source Technologies



                   Notes            •  An array in PHP is actually an ordered map. A map is a type that associates values to
                                      keys.

                                    •  The main difference in OOP as opposed to functional programming is that the data and
                                      code are bundled together into one entity, which is known as an object.

                                 7.11 Keywords


                                 Multi-Dimensional Arrays: When accessing nested arrays, you can just add as many square
                                 brackets as required to reach the relevant value. The following is an example of how you can
                                 declare nested arrays.
                                 Arrays: An array in PHP is a collection of key/value pairs. This means that it maps keys (or
                                 indexes) to values.
                                 Default Parameters: Default parameters like C++ are supported by PHP. Default Parameters
                                 enable you to specify a default value for function parameters that aren’t passed to the function
                                 during the function call.

                                 Returning Values By Reference: PHP also allows you to return variables by reference.
                                 Declaring Function Parameter: There are two different ways of passing these arguments. The
                                 first is the most common, which is called passing by value, and the second is called passing by
                                 reference. Which kind of argument passing you would like is specified in the function definition
                                 itself and not during the function call.

                                 By-Value  Parameters:  Here,  the  argument  can  be  any  valid  expression,  the  expression  is
                                 evaluated, and its value is assigned to the corresponding variable in the function.

                                 By-Reference Parameters: Passing by-reference requires the argument to be a variable. Instead
                                 of the variable’s value being passed, the corresponding variable in the function directly refers
                                 to the passed variable whenever used.

                                 Static Variables: Static variables can be initialized, and this initialization only takes place the
                                 first time the static declaration is reached.

                                 Accessing Array  Elements:  Array  elements  can  be  accessed  by  using  the  $arr[key]  notation,
                                 where key is either an integer or string expression.
                                 Objects: The main difference in OOP as opposed to functional programming is that the data
                                 and code are bundled together into one entity, which is known as an object.






                                            e’re going to implement a recursive function in MIPS. Recursion is one of those
                                            programming concepts that seem to scare students. One reason is that recursive
                                   Wfunctions can be difficult to trace properly without knowing something about
                                   how a stack works.
                                   “Classic” recursion attempts to solve a “big” problem by solving smaller versions of the
                                   problem, then using the solutions to the smaller versions of the problem to solve the big
                                   problem.
                                                                                                      Contd...



        122                               LOVELY PROFESSIONAL UNIVERSITY
   122   123   124   125   126   127   128   129   130   131   132