Using array_pad() with associative arrays : array_pad « Data Structure « PHP






Using array_pad() with associative arrays

 
<?php 
$dogs = array('A' => 'C', 'B' => 'D', 'X' => 'Z'); 

$pups = array_pad($dogs, 5, 'mutt'); 

printf("right padding:%s", var_export($pups, TRUE)); 

$pups = array_pad($dogs, -5, 'mutt'); 

printf("left padding:%s", var_export($pups, TRUE)); 

printf("Dogs:%s", var_export($dogs, TRUE)); 
?>
  
  








Related examples in the same category

1.Add new values to the beginning of the array by using a negative value for $size:
2.An array that is padded from the front
3.Setting an Array's Size: array array_pad(array $input, int $size, mixed $value)
4.array_pad 1
5.array_pad 2
6.array_pad 3
7.array_pad() function expands an array to a precise size, padding it with a default value.
8.Pad array to the specified length with a value