<?php
//adds an element to the beginning of an array
$prices = array(5.95, 10.75, 11.25);
printf("
%s
\n", implode(',', $prices));array_unshift($prices, 10.85);
printf("
%s
\n", implode(',', $prices));array_unshift($prices, 3.35, 17.95);
printf("
%s
\n", implode(',', $prices));?>
New
<?php
function array_insert(&$array, $offset, $new)
{
array_splice($array, $offset, 0, $new);
}
$languages = array('German', 'French', 'Spanish');
printf("
%s\n", var_export($languages, TRUE));
array_insert($languages, 1, 'Russian');
printf("
%s\n", var_export($languages, TRUE));
array_insert($languages, 3, 'Mandarin');
printf("
%s\n", var_export($languages, TRUE));
array_insert($languages, 2, 'Korean');
printf("
%s\n", var_export($languages, TRUE));
?>
No comments:
Post a Comment