Você está na página 1de 5

AULA 4 ESCOPO DE VARIVEIS <?php $a = Ol, mundo!; function Ola( ) { $a = Ol, amigo; $b = Como voc est?

; } Ola( ); echo $a; echo $b; ?> <?php $a = Ol; $b = Mundo; function Ola( ) { echo $GLOBALS['a'] . ' ' . $GLOBALS['b']; } Ola( );

1) FUNO SEM PARMETROS <html> <head> <title>Exerccio 1 Estudando Funes</title> <meta charset=utf-8> </head> <body> <?php
/*Incio da funo*/

function escreverONome( ) { echo Leandro Siqueira; }


/*Fim da funo*/ /*-------------------------*/ /*Chamada da funo*/

echo Meu nome : . escreverONome( ); ?> </body>

2) FUNO COM PASSAGEM DE PARMETROS POR VALOR SEM RETORNO NA PRPRIA <html> <head> <title>Exerccio 2 Estudando Funes</title> <meta charset=utf-8> </head> <body> <?php
/*Incio da funo*/

function somarValores($x, $y ) { echo A soma entre .$x. e .$y. igual a .$x+$y; }


/*Fim da funo*/ /*-------------------------*/ /*Chamada da funo*/

somarValores(5,4); ?> </body> </html>

3) FUNO COM PASSAGEM DE PARMETROS POR VALOR SEM RETORNO NA PRPRIA <html> <head> <title>Exerccio 3 Estudando Funes</title> <meta charset=utf-8> </head> <body> <?php /*Incio da funo*/ function inverteValores ($a, $b) { $troca = $a; $a = $b; $b = $troca; }/*Fim da funo*/
/*Declarao das variveis*/

$x = 10; $y = 100;
/*Chamada da funo*/

inverteValores($x,$y);

/*Imprimindo valores*/

echo $x."<br>"; echo $y; ?> </body> </html> FUNO SEM PASSAGEM DE PARMETROS COM RETORNO DE VALOR <html> <head> <title>Exerccio 4 </title> </head> <body> function OlaMundo( ) { return Ol, mundo!; } $txt = OlaMundo( ); echo $txt; </body> 4) FUNO COM PASSAGEM DE PARMETROS POR VALOR COM RETORNO DE VALOR <html> <head> <title>Exerccio 3 Estudando Funes</title> <meta charset=utf-8> </head> <body> <?php
/*Incio da funo*/

function somaValores ($a,$b) {


/*Armazenando na varivel resultado a soma entre as duas variveis*/

$resultado = $a + $b; return $resultado; /*Retornando o resultado*/ } /*Fim da funo*/


/*Declarao das variveis*/

$x = 10; $y = 100;
/*Imprimindo o resultado com a chamada da funo*/

echo "O resultado da soma igual a ". somaValores($x,$y); ?> </body> </html>

4) FUNO COM PASSAGEM DE PARMETROS POR REFERNCIA SEM

RETORNO <html> <head> <title>Exerccio 4 Estudando Funes</title> <meta charset=utf-8> </head> <body> <?php
/*Incio da funo*/

function inverteValores (&$a, $b) { $troca = $a; $a = $b; $b = $troca; }/*Fim da funo*/
/*Declarao das variveis*/

$x = 10; $y = 100;
/*Chamada da funo*/

inverteValores($x,$y);
/*Imprimindo valores*/

echo $x."<br>"; echo $y; ?> </body> </html> 5) FUNO COM PASSAGEM DE PARMETROS POR REFERNCIA COM RETORNO <html> <head> <title>Exerccio 4 Estudando Funes</title> <meta charset=utf-8> </head> <body> <?php /*Incio da funo*/ function inverteValores (&$a, &$b) { $troca = $a; $a = $b; $b = $troca; return $a; return $b; }/*Fim da funo*/ /*Declarao das variveis*/ $x = 10;

$y = 100; /*Chamada da funo*/ inverteValores($x,$y); echo "O valor de x : ".$x."<br>"; echo "O valor de y : ".$y; ?> </body> </html> 5) UTILIZAO DO INCLUDE <html> <body> <?php include 'cabecalho.php';?> <h2>Bem vindo a aula</h2> </body> </html> 6) UTILIZAO DO INCLUDE 2
/*Arquivo variaveis.php*/

<?php $cor = 'vermelha'; $carro = 'BMW'; ?>


/*Arquivo chamandoVariaveis.php*/

<html> <body> <h1>Chamando as variveis</h1> <?php include variaveis.php; echo Eu possuo um $carro $cor; ?> </body> </html/>

Você também pode gostar