Grow your CSS skills. Land your dream job.

FOR loop with counter in variables

  • __
    # May 20, 2013 at 6:48 pm

    > I think the whole confusion is rooted in the way quotes have to be used. It sure confused me

    Remember, single-quotes ( `’` ) make literal strings – every character you type ( except “, but let’s not get into that right now) will be exactly as you see it.

    With double-quotes ( `”` ) , PHP will interpret variables and escape characters in the string. So,

    < ?php
    $var = ‘world';
    echo ‘Hello, $var'; # prints “Hello, $var”
    echo “Hello, $var”; #prints “Hello, world”

    # May 20, 2013 at 7:03 pm

    You can also be explicit by using `{}` like so:

    for( $i=1; $i<4; $i++ ) {
    if( get_field( “product_image_{$i}” ) ) {
    echo get_field( “product_image_{$i}” ); } }

    This way when you’re reading PHP code, it’s clear what is happening or what is expected to happen.

    # May 20, 2013 at 8:57 pm

    > Remember, single-quotes ( ‘ ) make literal strings – every character you type ( except , but let’s not get into that right now) will be exactly as you see it.

    > With double-quotes ( ” ) , PHP will interpret variables and escape characters in the string

    Ah, of course….one of the things in PHP that I completely forgot about. Fiddling with JS so much (where single quotes and double quotes are used depending on how I nest code within code usually…) made me forget all about that.

Viewing 3 posts - 16 through 18 (of 18 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".