ඔන්න macho! 🤓
අද අපේ PHP සින්හලෙන් series එකේ Lesson 4 එකට awa! 🌀
මේකේ අපි Loops, Arrays, සහ ඒවට practical use case එකක් — HTML Table එකක් හදා balamu! 😍
🔁 Loop එකෙන් Array එකක් dance කරමු!
Array එකක් කියන්නේ 👉 එකම variable එකක name එක යටතේ multiple values තියෙන "container" එකක්.
$fruits = ["Apple", "Banana", "Mango"];
["Apple", "Banana"]
["name" => "Chamika", "age" => 25]
Loop එක කියන්නේ 👉 එකම task එක repeat කරන හැටි.
PHP වල තියෙන loops:
for
while
foreach
for
Loop – Index-based Array එක loop කරන්න$fruits = ["🍎 Apple", "🍌 Banana", "🥭 Mango"]; for ($i = 0; $i < count($fruits); $i++) { echo $fruits[$i] . "<br>"; }
while
Loop – repeat while condition is true$counter = 0; while ($counter < 3) { echo "Count: $counter <br>"; $counter++; }
foreach
Loop – Arrays වලට best friend ❤️$colors = ["Red", "Green", "Blue"]; foreach ($colors as $color) { echo $color . "<br>"; }
foreach
වලින් පාරමු$user = [ "name" => "Chamika", "age" => 25, "country" => "Sri Lanka" ]; foreach ($user as $key => $value) { echo "$key: $value <br>"; }
$students = [ ["name" => "Kasun", "marks" => 85], ["name" => "Nimali", "marks" => 92], ["name" => "Amal", "marks" => 78] ]; ?> <table border="1" cellpadding="8"> <tr> <th>👤 Name</th> <th>📝 Marks</th> </tr> <?php foreach ($students as $student) { echo "<tr>"; echo "<td>{$student['name']}</td>"; echo "<td>{$student['marks']}</td>"; echo "</tr>"; } ?> </table>
🔁 Output එකට ලස්සන Table එකක් ගිහිං දිස්වෙයි!
👉 Functions – function
keyword 🧠
👉 Parameters, Return values 🔁
👉 Reusable logic එකක් හදන්න
👉 Form validate කරන real example එකක් 💡
Lesson 5 ekata "function + validation" setup එකක් ready karannada?
🔥 Comment ekak dagena yamu
Member since 2025-04-09 13:55:06
Comments
Please login to post a comment.
No comments yet. Be the first to comment!