Skip to content

Instantly share code, notes, and snippets.

View YurePereira's full-sized avatar
😀
Out sick

Yure Pereira YurePereira

😀
Out sick
View GitHub Profile
@YurePereira
YurePereira / getting_absolute_path.php
Created February 18, 2017 17:47
Pegando o caminho absoluto a partir da raiz da pasta publica do servidor
<?php
//Pegando o caminho absoluto a partir da raiz da pasta publica do servidor
$path = $_SERVER['DOCUMENT_ROOT'] . '\project-name\components\\';
$file = $path . 'header.php';
include($file);
@YurePereira
YurePereira / getting_absolute_path_with_realpath.php
Last active February 19, 2017 19:48
Pegando o caminho absoluto com a função realpath.
<?php
$pathFile = realpath('components'. DIRECTORY_SEPARATOR . 'header.php') ;
if ($pathFile) {
include($pathFile);
} else {
@YurePereira
YurePereira / using_include.php
Created February 26, 2017 15:09
Usando a função include no PHP
<?php
//Caminho do arquivo a ser incluído.
$path = '<path>/filename.php';
//Fazendo inclusão do arquivo.
include($path);
@YurePereira
YurePereira / using_require.php
Created February 26, 2017 15:15
Usando a função require no PHP.
<?php
//Caminho do arquivo a ser incluído.
$path = '<path>/filename.php';
//Fazendo inclusão do arquivo.
require($path);
@YurePereira
YurePereira / using_include_once_and_require_once.php
Created February 26, 2017 17:15
Usando include_once e require_once no PHP.
<?php
//Caminhos dos arquivos a serem incluídos.
$path1 = '<path>/filename_1.php';
$path2 = '<path>/filename_2.php';
//Usando a função include_once:
include_once($path1);
//O arquivo no $path1 não será incluído, pois ele já foi.
include_once($path1);
@YurePereira
YurePereira / using_array_merge_2.php
Created March 1, 2017 16:14
Usando a função array_merge no PHP exemplo 2
<?php
$listFrults1 = array('Pineapple', 'Cashew', 'Coconut', 'Orange');
$listFrults2 = array('Strawberry', 'Pear', 'Grape', 'Peach');
$listFrults3 = array('Lime', 'Apple', 'Kiwi Fruit', 'Mango');
$listFullFrults = array_merge($listFrults1, $listFrults2, $listFrults3);
print_r($listFullFrults);
@YurePereira
YurePereira / using_array_merge.php
Created March 1, 2017 16:20
Usando a função array_merge no PHP exemplo 2.
<?php
$listFrults1 = array(
'p' => 'Pineapple',
'c' => 'Cashew',
'a' => 'Apple',
'o' => 'Orange'
);
$listFrults2 = array(
's' => 'Strawberry',
@YurePereira
YurePereira / using_in_array.php
Last active March 1, 2017 22:13
Verificando se um valor existe dentro de um Array em PHP.
<?php
$listFrults = array(
'Pineapple',
'Cashew',
'Coconut',
'Orange',
'Strawberry'
);
@YurePereira
YurePereira / using_in_array_2.php
Last active March 1, 2017 22:12
Verificando se um valor existe dentro de um Array em PHP - Exemplo 2.
<?php
$listFrults = array(
'pineapple' => 100,
'cashew' => 900,
'orange' => 500,
'strawberry' => 230
);
if (in_array('900', $listFrults, true)) {
@YurePereira
YurePereira / using_array_key_exists.php
Created March 2, 2017 15:45
Verificando se uma chave existe dentro de um Array em PHP.
<?php
$listFrults = array(
'p' => 'Pineapple',
'c' => 'Cashew',
'a' => 'Apple',
'o' => 'Orange'
);
if (array_key_exists('a', $listFrults)) {