0
How to read php
i'm learning php. i wrote (from a book) <?php if(!empty($data)): ?> <ul> <?php foreach ($data as $dataprint): ?> <li><?= $dataprint ?></li> <?php endforeach ?> </ul> end such I can't understand colons on line 1 and 3 and also why is on line 4 written <?= $dataprint? > without "php" word and why is there equal marks in the next?
7 Answers
+ 6
It is not a recommended way to write PHP block using <? ... ?>, the example is written based on an installation of PHP where the shorthand syntax is enabled in php.ini (PHP configuration file).
Apart from code readability factor, we cannot assume that shorthand option is enabled in any server, using the shorthand syntax may lead you into trouble when you try to host your PHP code where shorthand syntax is not enabled/active.
Avoid, at most, writing your script using shorthand syntax to have better compatibility with various PHP installation configuration.
Cheers...
+ 3
<?= $data means <?php echo $data
it's a shorthand
+ 1
oh i know, it is shorthand of <?php echo
+ 1
These probably are some typing errors.
There should be semicolon (;) instead of colon (:).
0
are you sure it is correct? as far as i know php need to be inside "<?php ?>" for processing it's operation
0
yeah sure.
i ran it and worked successfully
i just can't read those.
0
how about the equal?