SlideShare a Scribd company logo
1 of 20
Kurs PHP
Programski jezik za dinamicke web stranice
Predavanje 5
- If & else u PHP
- Switch
- For petlja
- While & do While petlja
- Foreach petlja
- .htaccess file primjer I koristenje
<?php echo ‘Recap’ ?>
Rjesenje zadace
https://github.com/newPrimitives/php-kurs/blob/master/lecture4/homeworkSolution.php
https://github.com/newPrimitives/php-kurs/blob/master/lecture4/homeworkSolutionBootstrap.php
<?php echo ‘Zadaca’ ?>
- Funkcija je izdvojeni dio koda čiji je zadatak primljene (ulazne) podatke
obradi u novi podatak koji se naziva rezultat funkcije.
- Sami podaci mogu biti različite prirode, kao što je broj, tekst, slika, zvuk
itd.
- Funkcija ne mora nuzno imati ulazne podatke
<?php echo ‘Funkcije’ ?>
- Pregledniji kod
- Izolacija jednog problema
- Izbjegavanje dupliranja istog koda u programu
<?php echo ‘Prednosti koristenja funkcija’ ?>
- Svaka funkcija ima ime, definiciju ulaznih podataka (argumenti),
definiciju izlaznih podataka (rezultat ) te tijelo funkcije
<?php echo ‘Generalni oblik funkcije’ ?>
# deklaracija funkcije I ulazni parametri
public function functionName($var1, $var2) {
# operacija
$var3 = $var1 + $var2
# izlazni podatak
return $var3
}
- PHP verzija 5.6.3 ima 1674 built in funkcije
<?php echo ‘Fun fact’ ?>
var_dump(get_defined_functions());
var_dump(phpinfo());
Primjer 1 – Osnove funkcija
https://github.com/newPrimitives/php-kurs/blob/master/lecture5/functionsBasic.php
<?php echo ‘Primjer’ ?>
Primjer 2 – Koristenje funkcija
https://github.com/newPrimitives/php-kurs/blob/master/lecture5/primjer1.php
<?php echo ‘Primjer’ ?>
- Skinuti rjesenje vjezbe 1 iz lekcije 2 (ili koristiti svoje postojece)
- Napisati funkciju koja prima array elemenata I vraca HTML listu
- Koristiti foreach petlju za iteraciju
- Pozvati funckiju iz HTML dijela stranice I ispisati njen rezultat
<?php echo ‘Vjezba 1’ ?>
- Funkcija u svojoj deklaraciji moze imati optional I required parametre
- Required parametri su parametri kojima se mora vrijednost dok optional
parametri ne mora imati vrijednost (default je null)
<?php echo ‘Optional I required varijable’ ?>
Primjer 3 – Optional I required parametri
https://github.com/newPrimitives/php-kurs/blob/master/lecture5/optionalVariables.php
<?php echo ‘Primjer’ ?>
- Jednostavni izraz $var1 = $var2 gdje vrijednost $var2 dodjeljujemo
$var1, rezervise u memoriji prostor za novu varijablu koja ima istu
vrijednost kao I $var2 (kopira vrijednost)
- $var1 = &$var2 kreira pointer (referencu) varijable $var2 u varijablu
$var1 sto znaci da je vrijednost $var1 I $var2 u memoriji spasena samo
jednom. Iz toga proizilazi da se mijenjanjem vrijenosti $var1 mijenja I
vrijednost $var2.
<?php echo ‘Value I reference pointeri’ ?>
- Ukoliko funkciji proslijedimo parametar/varijablu sa referencom bilo
koja promjena vrijednosti proslijedjene varijable unutar te funkcije ce
promijeniti I vrijednost te varijable van funkcije.
<?php echo ‘Reference’ ?>
Primjer 4 – Primjer proslijedjivanja reference
https://github.com/newPrimitives/php-kurs/blob/master/lecture5/passByReference.php
<?php echo ‘Primjer’ ?>
- Globalne varijable su one varijable koje su deklarisane u glavnom tijelu
koda, izvan svih funkcija dok su lokalne varijable one varijable koje su
deklarisane u funkciji ili nekom bloku (if; petlja).
<?php echo ‘Globalne I lokalne varijable’ ?>
Primjer 5 – Primjena funkcija
https://github.com/newPrimitives/php-kurs/blob/master/lecture5/paginationExample.php
<?php echo ‘Primjer’ ?>
- Napraviti clone 9gag-a (http://www.9gag.com)
- Deklarisati array slika sa stvarnim URLovima
- Deklarisati funkciju generateImg() koja kao parametar prima niz
- Koristiti funkciju paginate iz vjezbe 2 tako da se uvijek prikazuje samo
odredjeni broj slika
<?php echo ‘Zadaca’ ?>
- Definicija funkcije
- Sintaksa
- Primjeri koristenja
- Value I reference varijable
- Globalne I lokalne varijable
- Optional I required varijable
- Prakticna primjena (implementacija pagination funkcije)
<?php echo ‘To sum up’?>
<?php echo ‘Pitanja’?>

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

PHP za pocetnike - predavanje 5

  • 1. Kurs PHP Programski jezik za dinamicke web stranice Predavanje 5
  • 2. - If & else u PHP - Switch - For petlja - While & do While petlja - Foreach petlja - .htaccess file primjer I koristenje <?php echo ‘Recap’ ?>
  • 4. - Funkcija je izdvojeni dio koda čiji je zadatak primljene (ulazne) podatke obradi u novi podatak koji se naziva rezultat funkcije. - Sami podaci mogu biti različite prirode, kao što je broj, tekst, slika, zvuk itd. - Funkcija ne mora nuzno imati ulazne podatke <?php echo ‘Funkcije’ ?>
  • 5. - Pregledniji kod - Izolacija jednog problema - Izbjegavanje dupliranja istog koda u programu <?php echo ‘Prednosti koristenja funkcija’ ?>
  • 6. - Svaka funkcija ima ime, definiciju ulaznih podataka (argumenti), definiciju izlaznih podataka (rezultat ) te tijelo funkcije <?php echo ‘Generalni oblik funkcije’ ?> # deklaracija funkcije I ulazni parametri public function functionName($var1, $var2) { # operacija $var3 = $var1 + $var2 # izlazni podatak return $var3 }
  • 7. - PHP verzija 5.6.3 ima 1674 built in funkcije <?php echo ‘Fun fact’ ?> var_dump(get_defined_functions()); var_dump(phpinfo());
  • 8. Primjer 1 – Osnove funkcija https://github.com/newPrimitives/php-kurs/blob/master/lecture5/functionsBasic.php <?php echo ‘Primjer’ ?>
  • 9. Primjer 2 – Koristenje funkcija https://github.com/newPrimitives/php-kurs/blob/master/lecture5/primjer1.php <?php echo ‘Primjer’ ?>
  • 10. - Skinuti rjesenje vjezbe 1 iz lekcije 2 (ili koristiti svoje postojece) - Napisati funkciju koja prima array elemenata I vraca HTML listu - Koristiti foreach petlju za iteraciju - Pozvati funckiju iz HTML dijela stranice I ispisati njen rezultat <?php echo ‘Vjezba 1’ ?>
  • 11. - Funkcija u svojoj deklaraciji moze imati optional I required parametre - Required parametri su parametri kojima se mora vrijednost dok optional parametri ne mora imati vrijednost (default je null) <?php echo ‘Optional I required varijable’ ?>
  • 12. Primjer 3 – Optional I required parametri https://github.com/newPrimitives/php-kurs/blob/master/lecture5/optionalVariables.php <?php echo ‘Primjer’ ?>
  • 13. - Jednostavni izraz $var1 = $var2 gdje vrijednost $var2 dodjeljujemo $var1, rezervise u memoriji prostor za novu varijablu koja ima istu vrijednost kao I $var2 (kopira vrijednost) - $var1 = &$var2 kreira pointer (referencu) varijable $var2 u varijablu $var1 sto znaci da je vrijednost $var1 I $var2 u memoriji spasena samo jednom. Iz toga proizilazi da se mijenjanjem vrijenosti $var1 mijenja I vrijednost $var2. <?php echo ‘Value I reference pointeri’ ?>
  • 14. - Ukoliko funkciji proslijedimo parametar/varijablu sa referencom bilo koja promjena vrijednosti proslijedjene varijable unutar te funkcije ce promijeniti I vrijednost te varijable van funkcije. <?php echo ‘Reference’ ?>
  • 15. Primjer 4 – Primjer proslijedjivanja reference https://github.com/newPrimitives/php-kurs/blob/master/lecture5/passByReference.php <?php echo ‘Primjer’ ?>
  • 16. - Globalne varijable su one varijable koje su deklarisane u glavnom tijelu koda, izvan svih funkcija dok su lokalne varijable one varijable koje su deklarisane u funkciji ili nekom bloku (if; petlja). <?php echo ‘Globalne I lokalne varijable’ ?>
  • 17. Primjer 5 – Primjena funkcija https://github.com/newPrimitives/php-kurs/blob/master/lecture5/paginationExample.php <?php echo ‘Primjer’ ?>
  • 18. - Napraviti clone 9gag-a (http://www.9gag.com) - Deklarisati array slika sa stvarnim URLovima - Deklarisati funkciju generateImg() koja kao parametar prima niz - Koristiti funkciju paginate iz vjezbe 2 tako da se uvijek prikazuje samo odredjeni broj slika <?php echo ‘Zadaca’ ?>
  • 19. - Definicija funkcije - Sintaksa - Primjeri koristenja - Value I reference varijable - Globalne I lokalne varijable - Optional I required varijable - Prakticna primjena (implementacija pagination funkcije) <?php echo ‘To sum up’?>