03php array string functions

Upload: geshan-manandhar

Post on 30-May-2018

243 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 03PHP Array String Functions

    1/20

    GeshanManandhar.comGeshanManandhar.com 11

    PHP Day 3

    Geshan Manandhar

    Developer,Young Innovations Pvt. Limited

    www.geshanmanandhar.com

    http://www.php.net

  • 8/14/2019 03PHP Array String Functions

    2/20

    GeshanManandhar.com 2

    PHP StringsPHP Strings

    A string is series of characters.A string is series of characters.

    In PHP, a character is the same as a byte,In PHP, a character is the same as a byte,which is exactly 256 different characterswhich is exactly 256 different characters

    possible.possible.?>

  • 8/14/2019 03PHP Array String Functions

    3/20

    GeshanManandhar.com 3

    PHP StringsPHP Strings

    Another ExampleAnother Example

    ?>

  • 8/14/2019 03PHP Array String Functions

    4/20

    GeshanManandhar.com 4

    Important String FunctionsImportant String Functions

    explode (string $delimiter, string $string)(string $delimiter, string $string)

    nl2brnl2br ( string $string )( string $string )

    strcmpstrcmp ( string $str1, string $str2 )( string $str1, string $str2 )

    strlenstrlen ( string $string )( string $string )

    strtolowerstrtolower ( string $str )( string $str )

    substrsubstr ( string $string, int $start [, int( string $string, int $start [, int

    $length] )$length] ) trimtrim ( string $str )( string $str )

    Example code atExample code atday03\prog22_string_functions.phpday03\prog22_string_functions.php

    http://localhost/php_class/day03http://localhost/php_class/day03http://localhost/php_class/day03
  • 8/14/2019 03PHP Array String Functions

    5/20

    GeshanManandhar.com 5

    ArrayArray

    In computer science an array is a dataIn computer science an array is a datastructure consisting of a group of elementsstructure consisting of a group of elementsthat are accessed by indexing.that are accessed by indexing.

    In most programming languages eachIn most programming languages eachelement has the same data type and theelement has the same data type and thearray occupies a contiguous area of storage.array occupies a contiguous area of storage.

    Most programming languages have a built-inMost programming languages have a built-in

    array data type.array data type.

  • 8/14/2019 03PHP Array String Functions

    6/20

  • 8/14/2019 03PHP Array String Functions

    7/20

    GeshanManandhar.com 7

    Multi-Dimensional ArrayMulti-Dimensional Array

    //full code at day03\prog24_array_multi.php?> //full code at day03\prog24_array_multi.php

  • 8/14/2019 03PHP Array String Functions

    8/20

    GeshanManandhar.com 8

    Important Array Function:Important Array Function:

    asortasort asort($array) Sort an array and maintainasort($array) Sort an array and maintain

    index associationindex association

    ?>

  • 8/14/2019 03PHP Array String Functions

    9/20

    GeshanManandhar.com 9

    Important Array Function:Important Array Function:

    push/poppush/pop array_push($array,array_push($array,

    element1,)element1,)

    ?>

    array_pop($array)array_pop($array)

  • 8/14/2019 03PHP Array String Functions

    10/20

    GeshanManandhar.com 10

    Important Array Function:Important Array Function:

    searchsearch array_search($array, item1, item2);array_search($array, item1, item2);

    ?>

  • 8/14/2019 03PHP Array String Functions

    11/20

    GeshanManandhar.com 11

    Important Array Function :Important Array Function :

    randrand array_random ($array, no_of_entries);array_random ($array, no_of_entries);?>

  • 8/14/2019 03PHP Array String Functions

    12/20

    GeshanManandhar.com 12

    Important Array Function :Important Array Function :

    reversereverse

    array_reverse($array)array_reverse($array)

    ?>

  • 8/14/2019 03PHP Array String Functions

    13/20

    GeshanManandhar.com 13

    Important Array Function :Important Array Function :

    mergemergearray_merge($array1, $array2);array_merge($array1, $array2);

    ?>

  • 8/14/2019 03PHP Array String Functions

    14/20

    GeshanManandhar.com 14

    Important Array Function:Important Array Function:

    keyskeys array_keys($array, param)array_keys($array, param)

    ?>

  • 8/14/2019 03PHP Array String Functions

    15/20

  • 8/14/2019 03PHP Array String Functions

    16/20

    GeshanManandhar.com 16

    Some Date examplesSome Date examples

    ?>

  • 8/14/2019 03PHP Array String Functions

    17/20

    GeshanManandhar.com 17

    Important DebuggingImportant Debugging

    FunctionsFunctionsprint_rprint_r

    Prints human-readable information aboutPrints human-readable information abouta variablea variable

    var_dumpvar_dump Dumps information about a variableDumps information about a variable

    die() or exit()die() or exit() Dumps information about a variableDumps information about a variable

  • 8/14/2019 03PHP Array String Functions

    18/20

    GeshanManandhar.com 18

    The more you dig in the moreThe more you dig in the more

    you find outyou find out

    Find out other built in functions in PHPFind out other built in functions in PHPyourself.yourself.

    Search atSearch at

    www.php.netwww.php.net

    for more.for more.

    http://www.php.net/http://www.php.net/http://www.php.net/
  • 8/14/2019 03PHP Array String Functions

    19/20

    GeshanManandhar.com 19

    QuestionsQuestions

    Put forward your queries.Put forward your queries.

  • 8/14/2019 03PHP Array String Functions

    20/20

    GeshanManandhar.com 20

    Lets get rollingLets get rolling

    Print todays date like Today is: December 18, 2008Print todays date like Today is: December 18, 2008

    and time is 12:10:10 PM.and time is 12:10:10 PM.

    Reverse this sentence $str= PHP learn to want I Reverse this sentence $str= PHP learn to want I into a meaningful sentence, with use ofinto a meaningful sentence, with use of

    array_reverse.array_reverse.

    Learning PHP is not that easy and not that difficultLearning PHP is not that easy and not that difficult print it in lower and upper case with its string print it in lower and upper case with its stringlength.length.