How to read php | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

8th Dec 2017, 9:31 AM
Putri Alvina Lutfiani
Putri Alvina Lutfiani - avatar
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...
8th Dec 2017, 12:29 PM
Ipang
+ 3
<?= $data means <?php echo $data it's a shorthand
8th Dec 2017, 12:06 PM
Andika Romansyah
+ 1
oh i know, it is shorthand of <?php echo
8th Dec 2017, 9:56 AM
Andika Romansyah
+ 1
These probably are some typing errors. There should be semicolon (;) instead of colon (:).
8th Dec 2017, 11:54 AM
dunfc
dunfc - avatar
0
are you sure it is correct? as far as i know php need to be inside "<?php ?>" for processing it's operation
8th Dec 2017, 9:44 AM
Andika Romansyah
0
yeah sure. i ran it and worked successfully i just can't read those.
8th Dec 2017, 9:46 AM
Putri Alvina Lutfiani
Putri Alvina Lutfiani - avatar
0
how about the equal?
8th Dec 2017, 10:03 AM
Putri Alvina Lutfiani
Putri Alvina Lutfiani - avatar