php tutorial (3). working with arrays – strings in php what is an array

13
PhP Tutorial (3)

Upload: susan-harper

Post on 24-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

PhP Tutorial (3)

Page 2: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP• What is an Array

Page 3: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP• Creating Associative Arrays

Page 4: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP• Creating Multidimensional Arrays

Page 5: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP• Looping or Iterating Over Arrays

Page 6: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP• Array Functions Reference list

Function Description

array_change_key_case() Change all key case

array_chunk() Returns a multidimensional array of the chunked array

array_combine() Combine two arrays, one array becomes the keys and the other the values

array_count_values() Count values in an array

array_diff() Evaluate the difference in arrays

array_fill_keys() Specify keys of an array as it gets values put into it

array_fill() Fill an array with values specifying starting index and fill value

array_filter() Filters elements

array_flip() Swap all keys with their values

array_intersect() Evaluate the intersection of arrays

array_key_exists() Checks if the given key or index exists

array_keys() List all keys

Page 7: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP• Array Functions Reference list

Function Descriptionarray_merge_recursive() Recursively merge elements from two or more arrays

array_merge() Merge the elements from one or more arrays

array_multisort() Sort multiple arrays

array_pad() Pad an array to match a given length

array_pop() Pop the last element off the end

array_product() Get the product of values

array_push() Add to the end of an array

array_rand() Get random items from an array

array_reduce() Reduce the array to a single value

array_replace_recursive() Replace array data recursively

array_replace() Replace array data

array_reverse() Reverse an array

array_search() Returns the key of values searched for and found in an array

Page 8: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP• Array Functions Reference list

Function Description

array_shift() Remove the first element in an array and return the value

array_slice() Remove a specified element of an array

array_splice() Replace a specified element of an array

array_sum() Evaluate the sum of values in an array

array_unique() Removes duplicate values from an array

array_unshift() Add elements to the beginning of an array

array_values() Return all the values of an array

array_walk_recursive() Run a function recursively on every item of an array

array_walk() Run a function on every item of an array

arsort() Sort an array in reverse and maintain index association

asort() Sort an array and maintain index association

compact() Uses variable names as keys and their values as array values

count() Count elements in an array

Page 9: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP• Array Functions Reference list

Function Description

current() Return the current element

each() Return the current key value pair

end() Move the internal pointer to the last element in an array

extract() Create PHP variables with values from an array

in_array() Checks if a value exists in an array

key() Get a key from an array

krsort() Sort an array by key in reverse order

ksort() Sort an array by key

list() Create a list of variables from an array

natcasesort() Sort an array using a case insensitive natural order algorithm

natsort() Sort an array using a natural order algorithm

next() Move the internal pointer of an array ahead

pos() See current()

prev() Move the internal pointer of an array backward

Page 10: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP• Array Functions Reference list

Function Description

range() Returns an array made up of a range of elements from an original array

reset() Move the internal pointer of an array to the first element

rsort() Sort an array in reverse order

shuffle() Randomly shuffle an array

sizeof() See count()

sort() Sort an array

uasort() Sort an array with a user defined comparison

uksort() Sort an array by keys with a user defined comparison

usort() Sort an array by values with a user defined comparison

Page 11: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP

• Working With Strings and Numbers• What is the string?? A string is any one or set of alphanumeric characters and spaces.

E.g. Validate Email Addresses With PHP preg_match() and a Regex

Page 12: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Working with Arrays – Strings in PHP• Selected String Functions

String Function Description

addcslashes() Adds slashes to a string in C style

chunk_split() Returns a string split into chunks

count_chars() Count occurances of a target character in a string

explode() Splits a string and returns an array of the parts

Page 13: PhP Tutorial (3). Working with Arrays – Strings in PHP What is an Array

Assignments

• Run All functions List for:– Array function list– String Function List– Math Function List