January 31st, 2013, 06:00 AM
I am working on a website based on wordpress, and i want to generate a table automatically wich will be having a 3 columns width. I want to use a foreach because it uses an external file to serve as "theme" for the content i want within each cell... and i have to do a cicle that, each 3 "<td>" will make a "<tr>"
In c# i would use
but in php it doesn't work. How can i do this?
January 31st, 2013, 06:06 AM
Comments on this post
January 31st, 2013, 06:14 AM
Thanks for the reply, but that didn't help me much.
The problem is: i read that and got nothing of it. I'm really a noob at programming, and i never did web programming before. i don't really know how to do this. Also i see no similarities between php and c#(i know that that is normal)...
January 31st, 2013, 05:19 PM
What you need is actually a for loop, not a foreach loop. A foreach loop is only for iterating over something like an array. I'm pretty sure that's true of C# too.
A for loop in PHP has the same syntax as a for loop in C#, however variables in PHP are different than variables in C#. First, they are always prefixed with a $ sign, and second they do not have types.
The thing is, that's a pretty fundamental concept of PHP, so it's kind of hard to understand how you'll be able to write "code" without having understood at least that much about variables. I think you should find a good introduction to PHP tutorial and work through it first so that you can learn those types of things.
foreach($i = 0; $i < 3; $i++)