Page 170 - Beginning PHP 5.3
P. 170
Part II: Learning the Language
print_r( $authors );
echo $nextCell;
print_r( array_splice( $authors, 2, 0, $arrayToAdd ) );
echo $nextCell;
print_r( $arrayToAdd );
echo $nextCell;
print_r( $authors );
echo $rowEnd;
echo “{$headingStart}2. Replacing two elements with a new
element{$headingEnd}”;
$authors = array( “Steinbeck”, “Kafka”, “Tolkien” );
$arrayToAdd = array( “Bronte” );
echo $rowStart;
print_r( $authors );
echo $nextCell;
print_r( array_splice( $authors, 0, 2, $arrayToAdd ) );
echo $nextCell;
print_r( $arrayToAdd );
echo $nextCell;
print_r( $authors );
echo $rowEnd;
echo “{$headingStart}3. Removing the last two elements{$headingEnd}”;
$authors = array( “Steinbeck”, “Kafka”, “Tolkien” );
echo $rowStart;
print_r( $authors );
echo $nextCell;
print_r( array_splice( $authors, 1 ) );
echo $nextCell;
echo “Nothing”;
echo $nextCell;
print_r( $authors );
echo $rowEnd;
echo “{$headingStart}4. Inserting a string instead of an array{$headingEnd}”;
$authors = array( “Steinbeck”, “Kafka”, “Tolkien” );
echo $rowStart;
print_r( $authors );
echo $nextCell;
print_r( array_splice( $authors, 1, 0, “Orwell” ) );
echo $nextCell;
echo “Orwell”;
echo $nextCell;
print_r( $authors );
echo $rowEnd;
echo ‘</table>’;
?>
</body>
</html>
132
9/21/09 9:00:20 AM
c06.indd 132 9/21/09 9:00:20 AM
c06.indd 132