Professional Documents
Culture Documents
array_multisort() lets you sort multiple related arrays at the same time,
preserving the relationship between the arrays. To use it, simply pass in a list of
all the arrays you want to sort:
array_multisort( $array1, $array2, ... );
$authors = array( “Steinbeck”, “Kafka”, “Tolkien”, “Dickens” );
$titles = array( “The Grapes of Wrath”, “The Trial”, “The Hobbit”, “A Tale of
Two Cities” );
$pubYears = array( 1939, 1925, 1937, 1859 );
array_multisort( $authors, $titles, $pubYears );
print_r ( $authors );
print_r ( $titles );
print_r ( $pubYears );
3. array_shift()– – Removes the first element from the start of an array and
returns its value (but not its key). To use it, pass the array in question to
array_shift(): (for both index and associative)
$myBook = array( “title” = > “The Grapes of Wrath”, “author” = > “John
Steinbeck”, “pubYear” = > 1939 );
echo array_shift( $myBook ) . “ < br/ > ”;
print_r( $myBook );
4. array_pop() — Removes the last element from the end of an array. (for
both index and associative)
$myBook = array( “title” = > “The Grapes of Wrath”, “author” = > “John
Steinbeck”, “pubYear” = > 1939 );
echo array_pop( $myBook ) . “< br/ >”;
print_r( $myBook );
Index
$authors = array( “Steinbeck”, “Kafka” );
$moreAuthors = array( “Tolkien”, “Milton” );
print_r( array_merge( $authors, $moreAuthors ) );
Associative
To convert a string to an array, you can use PHP ’ s handy implode() string
function.
print_r($new);