PHP - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

PHP

Description:

PHP is a widely-used Open Source general-purpose scripting language that is ... Example(ar15.php) res. Arrays & Array Functions (contd) array_pad(array,size,value) ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 33
Provided by: lawr7
Category:
Tags: php | ar15

less

Transcript and Presenter's Notes

Title: PHP


1
PHP
2
PHPHypertext-Preprocessor
  • What is PHP?
  • PHP is a widely-used Open Source
    general-purpose scripting language that is
    especially suited for Web development and can be
    embedded into HTML.

3
PHP (contd)
  • An introductory example
  • lthtmlgt   ltheadgt       lttitlegtExamplelt/titlegt 
     lt/headgt   ltbodygt       lt?php        echo "Hi,
    I'm a PHP script!"        ?gt   lt/bodygtlt/htmlgt

    res

4
What can PHP do?
  • PHP can collect form data, generate dynamic page
    content, or send and receive cookies.
  • It concentrates mainly in three areas
  • 1.Server-side scripting.
  • 2.Command line scripting
  • 3.Writing desktop applications

5
Arrays and Array Functions
  • What is an Array?
  • Arrays are essential for storing, managing,
    and operating on sets of variables. An array in
    PHP is actually an ordered map. A map is a type
    that maps values to keys.

6
Arrays Array Functions (contd)
  • Syntax
  • An array can be created by the array()
    language-construct. It takes a certain number of
    comma-separated key gt value pairs.
  • array( key gt value    , ...    )//
    key may be an integer or string// value may be
    any value

7
Arrays Array Functions (contd)
  • Example 1(ar1.php)
  • lt?phparr array("foo" gt "bar", 12 gt
    true)echo arr"foo" // barecho arr12  
     // 1?gt
    res

8
Arrays Array Functions (contd)
  • Example 2(ar2.php)
  • lt?phparr array("somearray" gt array(6 gt
    5, 13 gt 9, "a" gt 42))echo arr"somearray"6
       // 5echo arr"somearray"13   // 9echo
    arr"somearray""a"  // 42?gt
    res

9
Arrays Array Functions (contd)
  • Example 3(ar3.php)
  • lt?php// This array is the same as
    ...array(5 gt 43, 32, 56, "b" gt 12)//
    ...this arrayarray(5 gt 43, 6 gt 32, 7 gt 56,
    "b" gt 12)?gt
    res

10
Arrays Array Functions (contd)
  • Example 4(ar4.php)
  • arr array(5 gt 1, 12 gt 2)
  • The unset() function allows unsetting keys of
    an array
  • unset(arr5) // This removes the element
    from the arrayunset(arr)    // This deletes
    the whole array?gt
    res

11
Arrays Array Functions (contd)
  • Example 5(ar5.php)
  • Create a simple array.Now delete every
    item, but leave the array itself intact.
  • Append an item (note that the new key is 5,
    instead of 0 as you might expect).
  • Re-index.
    res

12
Arrays Array Functions (contd)
  • Example 6(ar6.php)
  • Illustration of multi dimensional array

  • res

13
Arrays Array Functions (contd)
  • array_change_key_case(array,case)
  • This function returns an array with all array
    KEYS in lower case or upper case.
  • Example(ar7.php) res

14
Arrays Array Functions (contd)
  • array_chunk(array,size,preserve_key)
  • This function splits an array into chunks of
    new arrays.
  • Example(ar8.php) res

15
Arrays Array Functions (contd)
  • array_diff(array1,array2,array3...)
  • This function compares two or more arrays, and
    returns an array with the keys and values from
    the first array, only if the value is not present
    in any of the other arrays.
  • Example(ar9.php) res

16
Arrays Array Functions (contd)
  • array_fill(start,number,value)
  • This function returns an array filled with the
    values you describe.
  • Example(ar10.php) res

17
Arrays Array Functions (contd)
  • array_flip(array)
  • This function returns an array with all the
    original keys as values, and all original values
    as keys.
  • Example(ar11.php) res

18
Arrays Array Functions (contd)
  • array_intersect(array1,array2,array3...)
  • This function compares two or more arrays, and
    returns an array with the keys and values from
    the first array, only if the value is present in
    all of the other arrays.
  • Example(ar12.php) res

19
Arrays Array Functions (contd)
  • array_key_exists(key,array)
  • This function checks an array for a specified
    key, and returns true if the key exists and false
    is the key does not exist.
  • Example(ar13.php) res

20
Arrays Array Functions (contd)
  • array_merge (array1,array2,array3...) This
    function merges one or more arrays into one array
    . It returns the resulting array.
  • Example(ar14.php) res

21
Arrays Array Functions (contd)
  • array_multisort(array1,array2,array3...)
  • This function returns a sorted array. You can
    assign one or more arrays. The function sorts the
    first array, and the other arrays follow, then,
    if two or more values are the same, it sorts the
    next array, and so on.
  • Example(ar15.php) res

22
Arrays Array Functions (contd)
  • array_pad(array,size,value)
  • This function inserts a specified number of
    elements, with a specified value, to an array.
  • Example(ar16.php) res

23
Arrays Array Functions (contd)
  • array_pop(array)
  • This function deletes the last element of an
    array.
  • Example(ar17.php) res

24
Arrays Array Functions (contd)
  • array_product(array)
  • This function calculates and returns the
    product of an array.
  • Example(ar18.php) res

25
Arrays Array Functions (contd)
  • array_push(array,value1,value2...)
  • This function inserts one or more elements to
    the end of an array.
  • Example(ar19.php) res

26
Arrays Array Functions (contd)
  • array_reverse(array,preserve)
  • This function returns an array in the reverse
    order.
  • Example(ar20.php) res

27
Arrays Array Functions (contd)
  • array_search(value,array,strict)
  • This function search an array for a value and
    returns the key.
  • Example(ar21.php) res

28
Arrays Array Functions (contd)
  • array_shift(array)
  • This function removes the first element from an
    array, and returns the value of the removed
    element.
  • Example(ar22.php) res

29
Arrays Array Functions (contd)
  • array_sum(array)
  • This function returns the sum of all the values
    in the array.
  • Example(ar23.php) res

30
Arrays Array Functions (contd)
  • array_unique(array)
  • This function removes duplicate values from
    an array.
  • Example(ar24.php)
    res

31
Arrays Array Functions (contd)
  • asort(array,sorttype)
  • This function sorts an array by the values. The
    values keep their original keys.
  • Example(ar25.php) res

32
Resource
  • http//www.w3schools.com/php/php_ref_array.asp
Write a Comment
User Comments (0)
About PowerShow.com