Php Data-structure Examples Add elements to the end of an array Use the index in square brackets to create new elements and or assign values Reference Array by index Elements of the enumerated array are numbers Array element navigationArray element navigationAn array called $dinner with numeric keys Array and scalar collision Array index Arrays Demo Assign elements from array to variables Assigning Array Values Autogeneration of Array Indexes Changing array values Comparing ArraysOperating on array elements Display an array array_combinearray_key_exists array_keysarray_diff_assocarray_fliparray_valuesUsing the array_unique () Function Array array_chunk Array shuffle array_unshift Using the array_intersect () Function Using the array_diff () Function array_merge_recursiveUsing the array_merge () Function array_randarray_searchArray count value array_reversearray_poparray_pusharray_padUsing the array_push () Function count() function can also be used to access certain elements in the array The count() Function Using_the array_shift () Function array_spliceUsing the array_slice () Function currentendin_arrayarray_multisortarray_sumnextAdding elements with [] Alternating table row colors Setting an Array's Size Getting array size Loops through an indexed array of fruit names and creates a new array with the count of each fruit name. Iterating an Array with foreach and while/list/each Using foreach to Iterate through an Array Looping through an Enumerated Array Looping Through a Compact Indexed Array Using for and count() Looping Through a Multidimensional Array Looping Through a Sparse Array Looping Through an Associative Array with foreach Looping Through the $_SERVER Array Looping through child elements with foreach() Looping through identically named elements with foreach() Looping with foreach() List array values rangerange(0,20,2) rangearsortSort associate array sort an associative array on the basis of keys asort () function retains the array's keys in the original state To reverse sort an enumerated array, use the rsort () function Using the sort () Function Using usort() to Sort a Multidimensional Array by One of Its Fields Using uasort() to Sort a Multdimensional Associative Array by One of Its Fields Using uksort() to Sort an Associative Array by the Length of Its Keys Bubble Sort Variation Sorting with sort() Insertion Sort Pass a second parameter to the sort functions to specify how you want the values sorted Shell Sort Sort an array in reverse order and maintain index association Functions for Sorting Arrays Sorting Multiple Arrays Sorting an Array by Its Keys Sorting an Array by Its Values Use asort() to sort by population. Use ksort() to sort by city name. Using sort to alphabetize array_multisort date sort krsort( ) function reverse sorts it by its keys while preserving the values krsort() functionksort( ) function sorts array by its keys while preserving the values ksort() function sorts an array according to its key values, maintaining the original index association. sort.php sort() function sorts array elements from lowest to highest value. A list of numbers using an array variable Arrays Converting an object to an array will convert properties to elements of the resulting array Create an array Creates an array with keys 0 through 3 Creating arrays with array() Creating multidimensional arrays with array() Creating numeric arrays with array() Setting up an associative array is similarly easy Demonstrate the Difference Between the Array '+' Operator and a True Array Union Using the array function to create an array of weekdays Using the array() Function Queue Handling Library Stack Handling Library array_chunk Combining Arrays array_combine Counts all the values of an array with array array_count_values (array input) array_count_values demo array_count_values() function counts the frequency of the values. Array Complement array_diff array_diff( ) function returns a new array containing all the values of array $arr1 that do not exist in array $arr2. array_diff_assoc Array filter Filtering Arrays Using array_filter() Using the array_filter() Function array_filter demo array_filter( ) filters elements through a function Using array_flip() to return a string back to its original value array_flip demo array_flip( ) exchanges all the keys in that array with their matching values array_flip() example array_flip() function exchanges all key and element values for the array. Counting Array Elements array insert Array Intersection array_intersect array_intersect( ) function returns a new array containing all the values of array $arr1 that exist in array $arr2. array_intersect_assoc Outputting Using array_values() and array_keys() for Backward Compatibility Return all the keys of an array with array array_keys (array input [, mixed search_value]) array_keys( ) returns an array of all the keys in that array array_keys() function returns an array containing all keys Checking a select menu submission value Checking for an element with a particular key Validating a drop-down menu with array_key_exists() Testing for the Existence of a Key in an Array Applying Functions to Array Elements Using array_map() Using array_map() and array_walk() together Using the array_map() Function Appending One Array to Another Using array_merge() and the + operator with associative arrays as well array_merge array_merge( ) function combines two or more arrays by renumbering numerical indexes and overwriting string indexes array_merge( ) retains array keys when possible. array_merge() and + operator array_merge() example array_merge() function merges 1 to N arrays together obtaining the union of two arrays array_merge_recursive array_multisort for Array Keys with a Given Value Add new values to the beginning of the array by using a negative value for $sizeAn array that is padded from the front Setting an Array's SizeUsing array_pad() with associative arrays array_pad 1 array_pad 2 array_pad 3 array_pad() function expands an array to a precise size, padding it with a default value. Pad array to the specified length with a value array_pop( ) returns the value from the end of the array while also removing it from the array. array to comma string Remove array elements Adding an Element to the End of an Array Adding array elements array_push( ) pushes value onto the end of the array array_push() function appends one or more values onto the end of the array. Push one or more elements onto the beginning of array Push one or more elements onto the end of array A Random-Image Script Using array_rand() array_rand mixed array_rand ( array arr [, int amount] ) Using the array_remove() function to remove several elements from the beginning and the end of an arrayRemoving One or More Arbitrary Array Elements Concisely reversing a string by word Return an array with elements in reverse order Reversing an Array Using array_reverse() array_reverse() function reverses the order of the array elements. Reversing a string by word Finding an element with a particular value Removing the First Element of an Array with array_shift() Removing the First or Last Element from an Array array_shift( ) function returns the value from the front of the array while also removing it from the array. array_shift() function operates much like array_pop() Extracting a Portion of an Arrayarray_slice Extract a slice of the array Inserting New Values to an Arrayarray_splice array_splice() function replaces the designated elements specified by the offset and the optional length input parameters with the elements in the optional array replacement_array. Inserting New Values at an Arbitrary Point in an Indexed Array array remove Remove all elements from positions 3 to (n 3)Remove a portion of the array and replace it with something else Remove the fifth and sixth elements from the arrayReplace the third and fourth elements with new elementsarray_sum Finding the Sum and Average of the Values in an Array To get the unique values in an arrayarray_unique( ) filters an array so that a value can only appear once. Working with Unique Values Adding an Element to the Beginning of an Array Adding an Element to the Beginning of an Arrayarray_unshift( ) function pushes value onto the start of the array array_unshift() function shifts the array to the right. Return all the values of an array array_values( ) returns an array of all the values in that array array_values() function returns an array containing all of the values constituting the input array. Getting and Displaying Counts of Array Values Applying Functions to Array Elements Using array_walk() Apply a user function to every member of an array. array_walk() function applies a function to several or all elements in an array. Reversing an Array Using arsort() arsort( ) function reverse sorts it by its values while preserving the keys arsort() function maintains the original index association and sorts the elements in reverse order. Sorting with arsort() After using asort()to return the array's elements to their original order asort( ) function sorts array by its values while preserving the keys asort() Constants asort() function works in the same way as sort() and preserves the array's original key/value associations. asort() functionSorting with asort() Use foreach, while and list to loop through associate array Arrays Using Associative Array Notation Reference the assiciate array element foreach statement is used to loop through an associative array Associative Arrays keyprint_rarray_intersect_assocAn array called $computers with numeric and string keys An array called $vegetables with string keys Argument Swapping Array to object Assigning and Comparing Building an array of defaults Creates an array with keys 'a', 'b' and 'c with values of 1, 2 and 3 as well as keys 0, 1 and 2 with values 'a', 'b', and 'c' Creating Arrays Creates an array that assigns keys 1 through 7 to the days of the week. Creating a Multidimensional Array Creating an associative array of shapes Obtaining Array Keys and Values Obtaining Array Keys with a Given Value One-based array index Displaying one value from an array Using both the array key and a passed-in value to modify each element value Using Variable Variables to Create Associations Compact variables Get the size of an array in PHP using the count() function Getting the Number of Lines in a File Using count() to Iterate Through an Array Using each() function in conjunction with list() each() function returns the key-value pair at the current pointer position and moves the pointer to the next element. Breaking Strings into Arrays with explode() Display year an individual was born Using the explode() Function Generating an ID with microtime() explode( ) function converts a string into an array using a separator value explode() function divides string into various elements, returning these elements in an array. explode.php Using explode() with date() Processing variable-length text fields Reading and Writing Comma-Separated Data Add the prefix pts to each array key and then make each variable that results into a reference. Extracting Values from Arrays with extract() extract( ) function converts elements into variables extract($points, EXTR_REFS|EXTR_PREFIX_ALL, 'pts'); extract($scores, EXTR_PREFIX_ALL, 'score'); Using extract on an associative array Using extract with the EXTR_PREFIX_ALL directive Using EXTR_PREFIX_ALL on a numeric array Consider the following block of code implode an array to form a string. implode( ) function converts an array into a string by inserting a separator between each element implode.php Using the implode() Function Making a string from an array with implode() Outputting an Array As a String Printing HTML table rows with implode() Repackage the contents of an array into a delimited string, Checking for an element with a particular value in_array( ) function return true if an array contains a specific value in_array() function is a control statement. Determining Whether an Element Is in an Array Locating Array Elements Is it an array Reversing an Array Using krsort() Sorting with ksort() Randomizing an Array Using shuffle(), kshuffle(), and array_rand() Reference element in multidimensional Arrays Defining a Multidimensional Array Displaying a Multidimensional Array using For each Accessing multidimensional array elements Creating Multidimensional Arrays Sorting Multidimensional Arrays Multidimensional array element value interpolation Displaying Multidimensional Arrays Displaying a multidimensional array Find the Maximum Value in a Multidimensional Array Generating fixed-width field data records without Manipulating multidimensional arrays reset() rewinds the internal pointer of the array back to the first element. rsort() function sorts the elements in reverse order. rsort.php shuffle( ) function randomizes the position of the elements shuffle.php function sizeof() returns the number of elements contained in an array. A stack with type restricted to int Stack in Use Parsing fixed-width records with unpack() Unpacking Values from Binary Data Using unpack() usort() sorts an array based on your own predefined criteria. Sorting an Array Using Comparison Functions

Php Code : A Random-Image Script Using Array_rand()

A Random-Image Script Using array_rand() in php

<HEAD><TITLE>A random image script</TITLE></HEAD>
    $images = array('image1.jpg', 'image2.jpg', 'image3.jpg');
    $rImage = array_rand($images)
<IMG SRC="<?php echo $images[$rImage]; ?>">