I have an array that sets a number for each animal. I want to create a loop which will auto-increment for however number of animals there are
$animal = array(
'dog' => 2,
'cat' => 4,
);
foreach($animal as $pet => $num) {
echo(sprintf('this is %s number $s', $pet, $num));
};
Ideally I want it to display
this is dog number 1
this is dog number 2
this is cat number 1
this is cat number 2
this is cat number 3
this is cat number 4
1 Answer