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
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.

Edited by Christian F.
Link to comment
Share on other sites

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. ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.