Last active
August 30, 2016 17:52
-
-
Save dz0/bbc504f343c707014154ea16645e6b44 to your computer and use it in GitHub Desktop.
PHP intro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <a href="http://kaunascoding.lt">kur mes?</a><br> | |
| <?php | |
| echo "Hello, World"; | |
| // išsaugokite C:\xampp\htdocs\hello.php | |
| // ir atsidaryt naršyklę: localhost/hello.php | |
| // kintamieji | |
| $kiek = 10; | |
| $kiek++; | |
| echo "<br>I have $kiek money.."; | |
| // sąlygos | |
| if($kiek > 5){ | |
| echo "<br>$kiek is more than 5"; | |
| } | |
| else echo "<br>poor guy.."; | |
| // masyvai | |
| $cars = array("Volvo", "BMW", "Toyota"); | |
| // var_dump( $cars ); | |
| // ciklai | |
| foreach($cars as $car){ | |
| // echo "<br>I want $car"; | |
| } | |
| for($i=0; $i<3; $i++){ | |
| $car = $cars[ $i ]; | |
| echo "<br>I want $i $car (<a href='?choice=$i'>imu</a>)"; | |
| ; | |
| } | |
| $nr = rand(0, 2); // parenkam atsitiktinį el. iš sąrašo | |
| if( array_key_exists("choice",$_REQUEST)){ | |
| $nr = $_REQUEST["choice"]; // parenkam nurodytą | |
| } | |
| echo "<br>I have ${cars[$nr]}"; | |
| // nuorodoje galima užkoduoti duomenis | |
| // pvz., http://localhost/hello.php?kas=jurgis | |
| // ?kas=jurgis&choice=1 -- vadinama "query string" | |
| if( array_key_exists("kas",$_REQUEST)){ | |
| $kas = strtoupper($_REQUEST["kas"]); | |
| echo "<br>Labas, $kas"; | |
| } | |
| // funkcijos | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment