Jump to content

Newbie Question on Syntax


vincej

Recommended Posts

I often see the colon ( : ) being used in syntax however, no amount of searching through my text books or checking php.net reveals to me exactly what this is used for, when it is used and the exact definition of it's value.

 

Intuitively it seems to mean ' or '  but I can't be sure when || is the proper operator for 'or'

 

Can anyone point me towards a url for a succinct explanation ?

 

thanks VJ

Link to comment
https://forums.phpfreaks.com/topic/218994-newbie-question-on-syntax/
Share on other sites

If you're talking about something like

echo isset($_POST['text']) ? "Field is {$_POST['text']}" : 'Field is not set';

 

That is ternary syntax, and is essentially shorthand for

if( isset($_POST['text']) ) {
     echo "Field is {$_POST['text']}";
} else {
     echo 'Field is not set';
}

 

More about it can be found on this page.

well I see it in VirtueMart a lot - I still don't get what it means , eg

 

<?php echo ps_product::image_tag( $product_thumb_image, 'class="browseProductImage" border="0" title="'.$product_name.'" alt="'.$product_name .'"' ) ?></a>

 

 

OR /

 

 

<td nowrap="nowrap" width="10%" align="right"><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_COMPANY') ?>: </td>

 

 

 

 

 

 

 

well I see it in VirtueMart a lot - I still don't get what it means , eg

 

<?php echo ps_product::image_tag( $product_thumb_image, 'class="browseProductImage" border="0" title="'.$product_name.'" alt="'.$product_name .'"' ) ?>

That is a static method call, ps_product is the class and image_tag() is the method.  Similar to an object method $object->method() except acting on a class staically instead of on an instance of the class.  Read up on OOP in the PHP manual:  http://us2.php.net/manual/en/language.oop5.php

 

<td nowrap="nowrap" width="10%" align="right"><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_COMPANY') ?>: </td>

That is just a : in the HTML, notice it isn't inside the PHP tags.

Well, this one here is pretty complicated . . .

<td nowrap="nowrap" width="10%" align="right"><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_COMPANY') ?>: </td>

 

It actually causes a colon to be echoed to the screen, like this :

 

:P

 

EDIT: Dang. AC beat me to this one.

 

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.