Jump to content

Printf ($format, ...) in table


ronnievanderstegen

Recommended Posts

Hi

 

I want to make a table that has table rows like this:

 

There are 3 horses in the sky.

There are 4 cows   in the stable.

There are 5 dogs    in the sea.

 

The numbers, the animal names and the places have to be placed neatly below each other, so therefore I probably need to use the <td></td>.

I tried using the printf ($format, $number, $animal, $place) function, and the array's 

 

$number=array(3,4,5);
$place=array(sky,stable,sea);

$animal=array(horses, cows, dogs);

 

But I only get one tablerow that says (, There are, Array, Array, in the, Array);

 

Can anyone please tell me what code I have to use to make this? Thanks already.

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/275048-printf-format-in-table/
Share on other sites

You should be using a foreach on this, yes. However, Timothy didn't make it clear as to how or why. Not sure where he got print_r from though...

 

Use the foreach to loop through one of the arrays, saving both the key and the value. Then use the key to reference the correct value from the other arrays as well. Then you can use sprintf to build the string inside the loop, after which you can echo it out wherever you need it.

Sure, I could do that, if you don't mind paying for my time?

 

Writing code is what I do for a living, after all. My intention for answering people on this forum is to help people learn, not do their work for them for free. I've given you the tools and references you need to (try to) figure this one out yourself. Now, go forth and prove thyself worthy of help!

 

After all, if you can't be bothered to spend the time on it, why should I?

 

Think about that. ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.