From 3a7045f4c8a00a709663f78477182949325aa5ae Mon Sep 17 00:00:00 2001 From: Lokesh Pereiro Date: Thu, 1 Sep 2022 15:54:38 +0200 Subject: [PATCH 1/7] print.php file created --- print.php | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 print.php diff --git a/print.php b/print.php new file mode 100644 index 0000000..d639205 --- /dev/null +++ b/print.php @@ -0,0 +1,3 @@ + \ No newline at end of file From d0fc44839199e4058b20aca47db86a1933dcd8a1 Mon Sep 17 00:00:00 2001 From: Lokesh Pereiro Date: Thu, 1 Sep 2022 18:05:05 +0200 Subject: [PATCH 2/7] new files --- iterators.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ print.php | 17 ++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 iterators.php diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..9b9a5ef --- /dev/null +++ b/iterators.php @@ -0,0 +1,50 @@ +"; +print "
---------- (i++) --------------
"; +for($i=1; $i<=5; $i++){ + #cuando la condicion es i<5: Hola se imprime 4 veces + // echo 'Hola
'; + + #Si la condicion es i<=5: 5 veces + // Concatenamos 123.. con el string Lokesh + echo $i . ' Lokesh
'; + + # Ojo, mucho con las condiciones..tiene que tener sentido con la variable definida sino entrmos en un bucle infinito +} + +for($i=0; $i"; +} +echo '
'; +for($i=0; $i--){ + echo $meses[$i]."
"; +} + +print "
---------- (i--) --------------
"; +for($i = 10; $i>= 1; $i--){ + echo $i . '
'; +} + +print "--- [ Ciclo While ] ---"; +print "
---------- (x++) --------------
"; +$x=1; +while($x <=10){ + echo $x ; + // Esto es necesario pra evitar el bucle infinito + $x++ . '
'; +} + +print "
---------- (x--) --------------
"; +$x=10; +while($x >=1){ + echo $x; + // Esto es necesario pra evitar el bucle infinito + $x--; +} +echo '
'; +print "
--- [ Ciclo DO While ] ---"; +print "
---------- (y++) --------------
"; + + +?> \ No newline at end of file diff --git a/print.php b/print.php index d639205..922c16d 100644 --- a/print.php +++ b/print.php @@ -1,3 +1,18 @@
'; + +// Acepta más de un resultado (a través de coma) +echo "Hola PHP, soy ","Lokesh Pereiro"; +echo '

'; + +$array1 = [1,2,3,4,5]; +#El var_dump nos da la info del array (o cualquier tipo de dato) de manera más detallada +var_dump($array1); +echo '

'; + +$array2 = ['aa','bb','cc','dd','ee']; +#El print_r nos da la info de los datos de manera que resulte fácil leerlo +print_r($array2); ?> \ No newline at end of file From 981d59527fef9f3283e02622771ff29e35e1f825 Mon Sep 17 00:00:00 2001 From: Lokesh Pereiro Date: Fri, 2 Sep 2022 14:14:58 +0200 Subject: [PATCH 3/7] Files created: dates, condiconales,iterators,types.php + arr folder --- arr/arreglos.php | 43 ++++++++++++++++++++++ condicionales.php | 0 dates_time.php | 43 ++++++++++++++++++++++ iterators.php | 54 ++++++++++++++++++++++++++- operators.php | 94 +++++++++++++++++++++++++++++++++++++++++++++++ print.php | 4 +- types.php | 61 ++++++++++++++++++++++++++++++ 7 files changed, 296 insertions(+), 3 deletions(-) create mode 100644 arr/arreglos.php create mode 100644 condicionales.php create mode 100644 dates_time.php create mode 100644 operators.php create mode 100644 types.php diff --git a/arr/arreglos.php b/arr/arreglos.php new file mode 100644 index 0000000..c6fa5ed --- /dev/null +++ b/arr/arreglos.php @@ -0,0 +1,43 @@ +"; +$arrIndex = array('nombre', 'edad', 'pais', 'profesion'); +echo $arrIndex[3]; + + +print '
'; +print "
--- [ #Arreglo Asociativo ] ---
"; +$arrAsoci = array('nombre'=>'Lokesh', 'edad'=>25, 'pais'=>'España', 'profesion'=>'Developer'); +echo $arrAsoci['edad']; +// echo $arrAsoci['nombre'] = 'Pepito'; + + +print '
'; +print "
--- [ #Arreglo Multidimensionales ] ---
"; +$amigos = [['Alex', 20], ['Pepe',19],['Sofia',18,array('España')]]; +// Acceder al arreglo pepe y su edad +echo $amigos[1][0] . ' --' . $amigos[1][1].'años'; +print '
'; +// Acceder al arreglo sofi, su edad y el pais +echo $amigos[2][0] . ' --' . $amigos[2][1].'años' . ' -- '. $amigos[2][2][0]; + +print '
'; +print "
--- [ #Contar Elementos Arreglo ] ---
"; +$meses = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dic']; + +// Cuantos elementos hay dentro del arreglo? +// echo count($meses); + +// Ordenar los meses, ojo, primero hay que imprimir los meses en patalla +rsort($meses); +// Si queremos acceder al último mes (= [12-1]-->11) +$ulti_mes = count($meses) -1; +// echo $meses[$ulti_mes]; + +// Recorrer los meses para poder ordenarlos +foreach($meses as $mes){ + echo '--*' . $mes . '
'; +} + + +?> \ No newline at end of file diff --git a/condicionales.php b/condicionales.php new file mode 100644 index 0000000..e69de29 diff --git a/dates_time.php b/dates_time.php new file mode 100644 index 0000000..a5989d3 --- /dev/null +++ b/dates_time.php @@ -0,0 +1,43 @@ +--------------------
'; +// Día +echo date('d') .'
'; +// Mes +echo date('m').'
'; +// Año +echo date('Y').'
'; +// Dia semana +echo date('l').'
'; + +print '--------------------< Mix All >--------------------
'; +// Puedes poner barra inclinada o guión +echo 'Día Hoy = '. date('d/m/Y').'
'; + + + +print '--------------------< Time >--------------------
'; +// h minuscula es en el formato 12hora; H mayuscula formato 24h +echo date('h').'
'; +echo date('i').'
'; +echo date('s').'
'; +echo date('a').'
'; +print '--------------------< Mix All >--------------------
'; +echo 'Hora Actual = '. date('H:m:s:a').'
'; + + +print '--------------------< Current Date & Time >--------------------
'; +echo date('m/d/Y H:i:sa'); +echo '

'; + + +print '--------------------< My BirthDay in Date & Time >--------------------
'; +// Primero va la hora, luego la fecha. Pero se imprimer al revés +$myBday = mktime(14,15,44,2,05,1997); +echo date('m/d/Y H:i:sa', $myBday); + +?> \ No newline at end of file diff --git a/iterators.php b/iterators.php index 9b9a5ef..a138526 100644 --- a/iterators.php +++ b/iterators.php @@ -1,5 +1,6 @@ "; print "
---------- (i++) --------------
"; for($i=1; $i<=5; $i++){ @@ -12,6 +13,7 @@ # Ojo, mucho con las condiciones..tiene que tener sentido con la variable definida sino entrmos en un bucle infinito } +echo '
'; for($i=0; $i"; @@ -26,6 +28,8 @@ echo $i . '
'; } + + print "--- [ Ciclo While ] ---"; print "
---------- (x++) --------------
"; $x=1; @@ -34,6 +38,14 @@ // Esto es necesario pra evitar el bucle infinito $x++ . '
'; } +echo '
'; + +$xyz = 0; + +while($xyz'; + $xyz++; +} print "
---------- (x--) --------------
"; $x=10; @@ -43,8 +55,46 @@ $x--; } echo '
'; + + + print "
--- [ Ciclo DO While ] ---"; -print "
---------- (y++) --------------
"; +print "
---------- (gg++) --------------
"; +// A diferencia de For loop y While, el Do While al menos se ejecuta una vez 'aunque falle la condicion' +// En nuestro caso, al menos nos imprime un 1 +$gg=1; + +do{ +echo $gg . '
'; +$gg++; +}while($gg == 50); + +echo '
'; + + + +print "
--- [ Ciclo ForEach] ---"; -?> \ No newline at end of file +$coche = ['nombre'=>'Seat', 'año'=>2018, 'color'=>'rojo', 'fabricacion'=> 'España'] +?> + + + + + Document + + +
    + '. $mes .''; + // } + foreach($coche as $propiedades => $valor){ + echo $propiedades.': ' . $valor.'
    '; + } + ?> +
+ + \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..f619d40 --- /dev/null +++ b/operators.php @@ -0,0 +1,94 @@ +"; +/* ++ Suma +- Resta +* Multi +/ Divi +% modulo(residuo) +*/ +$numero = 10; +$numero2 = 20; +echo $numero+$numero2; +print"
"; +echo $resul = $numero2 /= 2; + +print '
'; +print "
--- [ Operadores de Compración ] ---
"; +/* +== igual en valor +=== igual en valor y tipo de dato +!=, es valor es distinto a.. +!== el valor y el tipo de dato es distion a.. +> +< +>= +<= +*/ +$comprarAlcohol = 18; +if($comprarAlcohol>=18){ + echo 'Tienes edad para comprarlo...'; +} else{ + echo 'Lo siento, no te podemos venderlo'; +} +$booln = false; +$booln1 = 'false'; + +if($booln != $booln1){ + // Se ejecuta + echo 'Se ejecutó...'; +} else{ + echo 'NO se ejecuto...'; +} + +print '
'; +print "
--- [ Operadores Lógicos ] ---
"; +/* Operadores +$$ And +OR, || or +XOR +! negacion +*/ +$nombre = 'Pepe'; +// Solo se tiene que cumplir una condición, si se cumple ambos.. no se ejecuta +if($comprarAlcohol>= 18 XOR $nombre == 'Pepe'){ + Echo 'Bienvenido...'; +} else{ + echo 'No se ejecutó..'; +} + + +print "
--- [ Operadores de Asignación ] ---
"; +/* += igual o de asignacion ++= propio valor + algun valor de asignacion (Ex. $numero += 7 --> 17) +-= (Ex. $num3 -= 7 --> 10) +*= (Ex. $num4 *= 7 --> 140) +/= (Ex. $numero2 /= 2 --> 10) +*/ +$num3=10; +$num4=20; +echo $num3 -= 7; +print '
'; +echo $num4 *= 7; +print '
'; +echo $numero2 /= 2; + + + + +print "
--- [ Operadores de Asignación+Concatenar String ] ---
"; +// Con el .= tienes que nombre las variables iguales +$texto = 'String, más,'; +$texto .= ' Otra cadena de Texto'; +echo $texto; + + +/* Operadores Incremento/Decremento +++$x +$x++ +--$y +$y-- + +*/ +?> \ No newline at end of file diff --git a/print.php b/print.php index 922c16d..a0bc1ac 100644 --- a/print.php +++ b/print.php @@ -1,6 +1,8 @@
'; // Acepta más de un resultado (a través de coma) diff --git a/types.php b/types.php new file mode 100644 index 0000000..fd6ae66 --- /dev/null +++ b/types.php @@ -0,0 +1,61 @@ +"; +$nombre = 'Pepito'; +echo var_dump($nombre); + +print '
'; +print "
--- [ Numero(integer) ] ---
"; +$numero = 10; +echo var_dump($numero); + +print '
'; +print "
--- [ Numero(float) ] ---
"; +$numero_decimal = 10.999; +echo var_dump($numero_decimal); + +print '
'; +print "
--- [ Boolean ] ---
"; +$verdadero = true; +/* true = 1, false = 0 */ +echo var_dump($verdadero); +echo gettype($verdadero); + + +print '
'; +print "
--- [ NULL ] ---"; +// Cuando una variables aun no está asignada (No es 'Undefined') +$apellido; +// echo var_dump($apellido); +echo gettype($apellido); + +print '
'; +print "
--- [ Array ] ---
"; +// Puedes almacenar cuallquier tipo de datos.. +// Sintaxis tradicional +$diasSemana = array('Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sábado', 'Domingo'); +// Sintaxis nueva +$arr = ['string letras',2,true, array('abc',$xzy),5]; +echo $diasSemana[5]; /* Resultado: Sábado */ +// Se puede modificar los elementos del arreglo simplemente recorriendo su posición y/o añadirlos al final según el index +// echo $diasSemana[0] = 'Lokesh'; +// echo $diasSemana[0]; +// echo $diasSemana[7] = 'Pereiro'; + +print '
'; +print "
--- [ Object ] ---
"; + + + +print '
'; +print "
--- [ Constantes ] ---
"; +// Las constantes se definen en un método 'define(nombre, valor)' +//Son variables globales que podemos acceder a ella desde cualquier archivo +// Por lo tanto son únicas y no se puede reescribirlas. Se recomienda escribirlas en mayusculas. +define('NOMBRE', 'Lokesh'); +define('PI', '3.14'); +// define('Nombre', 'Pepe'); +echo NOMBRE .'
'; +echo PI; + + +?> \ No newline at end of file From 97b532e7f51a48921ecffbf084c86bd0e175cc2a Mon Sep 17 00:00:00 2001 From: Lokesh Pereiro Date: Sat, 3 Sep 2022 19:11:03 +0200 Subject: [PATCH 4/7] Finished files upload --- arr/arreglos.php => arrays.php | 55 +++++++++++++++--- condicionales.php | 71 +++++++++++++++++++++++ dates.php | 42 ++++++++++++++ dates_time.php => dates_traditional.php | 0 funciones.php | 65 +++++++++++++++++++++ iterators.php | 8 ++- math.php | 75 +++++++++++++++++++++++++ operators.php | 8 +++ phpinfo.php | 5 ++ print.php | 16 ++++-- strings.php | 55 ++++++++++++++++++ types.php | 5 ++ 12 files changed, 389 insertions(+), 16 deletions(-) rename arr/arreglos.php => arrays.php (55%) create mode 100644 dates.php rename dates_time.php => dates_traditional.php (100%) create mode 100644 funciones.php create mode 100644 math.php create mode 100644 phpinfo.php create mode 100644 strings.php diff --git a/arr/arreglos.php b/arrays.php similarity index 55% rename from arr/arreglos.php rename to arrays.php index c6fa5ed..a28baf9 100644 --- a/arr/arreglos.php +++ b/arrays.php @@ -1,15 +1,13 @@ "; +print "--- [ #Arreglo Indexado - String ] ---
"; $arrIndex = array('nombre', 'edad', 'pais', 'profesion'); -echo $arrIndex[3]; - +echo var_dump($arrIndex[3]); +print '
'; print '
'; -print "
--- [ #Arreglo Asociativo ] ---
"; -$arrAsoci = array('nombre'=>'Lokesh', 'edad'=>25, 'pais'=>'España', 'profesion'=>'Developer'); -echo $arrAsoci['edad']; -// echo $arrAsoci['nombre'] = 'Pepito'; +print "--- [ #Arreglo Indexado - Numbers ] ---
"; +$arrIndex2 = array(3,2.2,6.99,8,25,99.99); +echo var_dump($arrIndex2[5]); print '
'; @@ -21,6 +19,46 @@ // Acceder al arreglo sofi, su edad y el pais echo $amigos[2][0] . ' --' . $amigos[2][1].'años' . ' -- '. $amigos[2][2][0]; +print '
'; +print "
--- [ #Arreglo Multidimensionales Lenght] ---
"; +echo count($amigos); + + +print '
'; +print "
--- [ #Funtion to Merge two Arrays] ---
"; +// Two Arrays in one sigle one +$mergeArr = array_merge($arrIndex, $arrIndex2); +// echo var_dump($mergeArr); +echo"
";
+    print_r($mergeArr); 
+echo"
"; + + +print "
--- [ #Function return last element of Array] ---
"; +// array_key_last() +// echo $lastEle = count($mergeArr)-1; +echo end($mergeArr); + + +print '
'; +print "
--- [ #Function to add/Push Elements in an array] ---
"; +$arrPush = ['Pepito',123, true]; +array_push($arrPush, 'Hola Pepito Push'); +print_r($arrPush); + + +print '
'; +print "
--- [ Extra Content Commented] ---
"; +/** + +print '
'; +print "
--- [ #Arreglo Asociativo ] ---
"; +$arrAsoci = array('nombre'=>'Lokesh', 'edad'=>25, 'pais'=>'España', 'profesion'=>'Developer'); +echo $arrAsoci['edad']; +// echo $arrAsoci['nombre'] = 'Pepito'; + + + print '
'; print "
--- [ #Contar Elementos Arreglo ] ---
"; $meses = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dic']; @@ -39,5 +77,6 @@ echo '--*' . $mes . '
'; } +**/ ?> \ No newline at end of file diff --git a/condicionales.php b/condicionales.php index e69de29..5e13fe4 100644 --- a/condicionales.php +++ b/condicionales.php @@ -0,0 +1,71 @@ +--------------------
'; + +$currentDay = new DateTime(); +// echo $currentDay->format('Y/m/d H:i:sA l'); + + +if($currentDay ->format('l') === 'Monday'){ + echo 'We are on Monday'; +} else{ + echo "No, today ". $currentDay->format('l'); +} + +echo '
'; +print '
--------------------< Current Month >--------------------
'; + +if($currentDay ->format('M') === 'October'){ + echo 'We are on October'; +} else{ + echo "No, We are on ". $currentDay->format('M');; +} + +echo '
'; +print '
--------------------< Current Month >--------------------
'; + +// $currentDay->setTime(18,12); + +if($currentDay->format('i')<10){ + echo 'The current minutes is less than 10'; +} else if($currentDay->format('i')>15){ + echo 'The current minutes is more than 15'; +} else { + echo 'Does not meet any conditions'; +} + +// echo $currentDay->format('l'); + +// $currentDay->setTime(18,12); +echo '
'; +print '
--------------------< Switch >--------------------
'; +switch($currentDay->format('l')){ + case 'Monday':{ + echo 'Not a weekend day, must study and/or work!'; + break; + } + case 'Tuesday':{ + echo 'Not a weekend day, must study and/or work!'; + break; + } + case 'Wednesday':{ + echo 'Not a weekend day, must study and/or work!'; + break; + } + case 'Thusday':{ + echo 'Not a weekend day, must study and/or work!'; + break; + } + case 'Friday':{ + echo 'Not a weekend day, we are close to it!'; + break; + } + case 'Saturday':{ + echo 'Its weekend, have fun!'; + break; + } + case 'Sunday':{ + echo 'Its weekend, have fun!'; + break; + } +} +?> \ No newline at end of file diff --git a/dates.php b/dates.php new file mode 100644 index 0000000..125f5cf --- /dev/null +++ b/dates.php @@ -0,0 +1,42 @@ +--------------------
'; +$dateTime = new DateTime(); +print ' (Y/m/d)
'; +echo $dateTime->format('Y/m/d'); +echo '
'; +var_dump($dateTime); +echo '
'; + + +echo '
'; +print '
--------------------< TimeZone-Madrid >--------------------
'; +// Set timezone Madrid so that we can print Europe/Madrid name insted of Europe/Berlin which is by default +$dateTime->setTimezone(new DateTimeZone('Europe/Madrid')); +echo $dateTime->getTimeZone()->getName().' -- '.$dateTime->format('d/m/Y H:i:s A'); +echo '
'; + +print '
--------------------< Numerical-Format-Month >--------------------
'; +echo $dateTime->format('m'); +echo '
'; +print '--------------------< Current-Minutes >--------------------
'; +echo $dateTime->format(' 00-i'); +echo '
'; +print_r($dateTime); + + + +echo '
'; +echo '
'; +print '--------------------< TimeZone:London --> Changing Date & Time >--------------------
'; +$dateTime->setTimezone(new DateTimeZone('Europe/London')); +print_r($dateTime); + +echo '
'; +echo '
'; + +$dateTime->setDate(1997, 4, 21)->setTime(2,15); +echo $dateTime->getTimeZone()->getName().' -- '.$dateTime->format('d/m/Y H:i:s A'); +echo '
'; + +?> \ No newline at end of file diff --git a/dates_time.php b/dates_traditional.php similarity index 100% rename from dates_time.php rename to dates_traditional.php diff --git a/funciones.php b/funciones.php new file mode 100644 index 0000000..e1e6fd5 --- /dev/null +++ b/funciones.php @@ -0,0 +1,65 @@ +"; +// } +// saludo(); + +print '
'; +print "--- [ #Funciones con parámetro: ADD ] ---
"; + +#Funciones con parámetro +function sumar($a, $b){ + echo $a + $b; +} +sumar(5,5); + +print '
'; +print "--- [ #Funciones con parámetro: Multiplicar ] ---
"; + +#Funciones con parámetro +function multi($a, $b){ + echo $a * $b; +} +multi(5,10); + +print '
'; +print "--- [ #Funciones con parámetro: Dividir ] ---
"; + +#Funciones con parámetro +function dividir($a, $b){ + echo $a / $b; +} +dividir(100,5); + + +print '
'; +print "--- [ #Operation with parameter received ] ---
"; + function operar($a, $operation, $b){ + if ($operation == "+") { + return $a + $b; + }else if ($operation == "*") { + return $a * $b; + }else if ($operation == "/") { + return $a / $b; + } else if ($operation == "%") { + return $a % $b; + } + } + + echo operar(4, '%', 3); + +print '
'; + + +/* +#Funiones con retorno +function retorno($rt){ + return $rt; +} +// Se neceesita echo para llamar la funcion y tu retornas lo que quieras () +// Utilizada en POO +echo retorno('retornar'); + +*/ +?> \ No newline at end of file diff --git a/iterators.php b/iterators.php index a138526..017a19d 100644 --- a/iterators.php +++ b/iterators.php @@ -10,8 +10,6 @@ #Si la condicion es i<=5: 5 veces // Concatenamos 123.. con el string Lokesh echo $i . ' Lokesh
'; - - # Ojo, mucho con las condiciones..tiene que tener sentido con la variable definida sino entrmos en un bucle infinito } echo '
'; @@ -30,6 +28,8 @@ + + print "--- [ Ciclo While ] ---"; print "
---------- (x++) --------------
"; $x=1; @@ -58,6 +58,8 @@ + + print "
--- [ Ciclo DO While ] ---"; print "
---------- (gg++) --------------
"; // A diferencia de For loop y While, el Do While al menos se ejecuta una vez 'aunque falle la condicion' @@ -74,6 +76,8 @@ + + print "
--- [ Ciclo ForEach] ---"; $coche = ['nombre'=>'Seat', 'año'=>2018, 'color'=>'rojo', 'fabricacion'=> 'España'] diff --git a/math.php b/math.php new file mode 100644 index 0000000..0da428f --- /dev/null +++ b/math.php @@ -0,0 +1,75 @@ +'; +// Exponentes function: cuadrados, cubos, etc. +echo pow(5,2); +echo'
'; +// Raiz +echo sqrt(144); +echo'
'; +// Floor(redondeo hacia abajo) y Ceil(hacia arriba) +echo floor(4.3) . ' --- '; +echo ceil(4.3); + + + +echo '
'; +print '
--------------------< Absolute Value >--------------------
'; + $absoluteValue = -1.5; + echo $absFunciton = abs($absoluteValue); + + +echo '
'; +print '
--------------------< Rounded Value >--------------------
'; +$roundValue = 1.6; +echo $roundFunction = round($roundValue); + + +echo '
'; +print '
--------------------< Highest Value >--------------------
'; +// $highestNum = (max(2,0,-2,200,180,-55,1)). '
'; +// $lowestNum (min(2,0,-2,200,180,-55,1)); +$arr = array(2,0,-2,46,-1,150,580,-55,1); +// echo $max=$arr[0]; + +function getMaxValue($arr){ + // Variable max en la posicion 0 + $max=$arr[0]; + + for($i=1; $i'; +print '
--------------------< Lowest Value >--------------------
'; +function getMinValue($arr){ + // Variable max en la posicion 0 + $min=$arr[0]; + + for($i=1; $i $arr[$i]){ + $min = $arr[$i]; + } + } + return $min; +} +echo getMinValue($arr); + + echo '
'; + print '
--------------------< Random Value >--------------------
'; + // Nos devuelve numeros random pero muy grandes + // $randomValue = rand(); + // Nos devuelve numeros entre 1 y 50 + $randomValue = rand(1,50); + echo $randomValue; // <-- random integer +?> \ No newline at end of file diff --git a/operators.php b/operators.php index f619d40..ea19d51 100644 --- a/operators.php +++ b/operators.php @@ -1,5 +1,6 @@ "; + /* + Suma - Resta @@ -7,6 +8,7 @@ / Divi % modulo(residuo) */ + $numero = 10; $numero2 = 20; echo $numero+$numero2; @@ -15,6 +17,7 @@ print '
'; print "
--- [ Operadores de Compración ] ---
"; + /* == igual en valor === igual en valor y tipo de dato @@ -25,6 +28,7 @@ >= <= */ + $comprarAlcohol = 18; if($comprarAlcohol>=18){ echo 'Tienes edad para comprarlo...'; @@ -43,12 +47,14 @@ print '
'; print "
--- [ Operadores Lógicos ] ---
"; + /* Operadores $$ And OR, || or XOR ! negacion */ + $nombre = 'Pepe'; // Solo se tiene que cumplir una condición, si se cumple ambos.. no se ejecuta if($comprarAlcohol>= 18 XOR $nombre == 'Pepe'){ @@ -59,6 +65,7 @@ print "
--- [ Operadores de Asignación ] ---
"; + /* = igual o de asignacion += propio valor + algun valor de asignacion (Ex. $numero += 7 --> 17) @@ -66,6 +73,7 @@ *= (Ex. $num4 *= 7 --> 140) /= (Ex. $numero2 /= 2 --> 10) */ + $num3=10; $num4=20; echo $num3 -= 7; diff --git a/phpinfo.php b/phpinfo.php new file mode 100644 index 0000000..6480abf --- /dev/null +++ b/phpinfo.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/print.php b/print.php index a0bc1ac..07a6890 100644 --- a/print.php +++ b/print.php @@ -1,19 +1,23 @@ "; $nombre='Lokesh'; -print "Hola, $nombre"; -echo '

'; - // Acepta más de un resultado (a través de coma) echo "Hola PHP, soy ","Lokesh Pereiro"; -echo '

'; +print '
'; +print "
--- [ #Print ] ---
"; +print "Hola, $nombre"; + +echo '
'; +echo "
--- [ #Var_dump ] ---
"; $array1 = [1,2,3,4,5]; #El var_dump nos da la info del array (o cualquier tipo de dato) de manera más detallada var_dump($array1); -echo '

'; +echo '
'; +print "
--- [ #Print_r ] ---
"; $array2 = ['aa','bb','cc','dd','ee']; #El print_r nos da la info de los datos de manera que resulte fácil leerlo print_r($array2); diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..de485c6 --- /dev/null +++ b/strings.php @@ -0,0 +1,55 @@ +--------------------< Simple String Text >--------------------
'; +echo 'Hi, Im String Text'; + +echo '
'; +print '
--------------------< Varible String>--------------------
'; +$string = 'Im a variable that contain String'; +echo $string; + +echo '
'; +print '
--------------------< Concatenate String>--------------------
'; +echo "Concatenate previous string that says: ". $string; + +echo '
'; +print '
--------------------< Replace String (Case sensitive) >--------------------
'; +$abc='Replace the word cat'; +echo str_replace('cat', 'dog', $abc); + +echo '
'; +print '
--------------------< Replace String (NOT Case sensitive) >--------------------
'; +$ac='Replace the word Notsensitive'; +echo str_ireplace('notsensitive', 'NOTSENSITIVE', $ac); + + +echo '
'; +print '
--------------------< Repeat String N times >--------------------
'; +$hello='Hello'; +echo 'Repeat Hello 5x: '.str_repeat($hello, 5); + + +echo '
'; +print '
--------------------< String Length >--------------------
'; +$helloDog='Hello Dog'; +echo 'The variable HelloDog has: '.strlen($helloDog). ' characters.'; + +echo '
'; +print '
--------------------< String Position Characters >--------------------
'; +$cat='Cat'; +echo strpos($cat, 't'); + +echo '
'; +print '
--------------------< String Uppercase >--------------------
'; +$dummy='dumppytext'; +echo strtoupper($dummy); + +echo '
'; +print '
--------------------< String Lowercase >--------------------
'; +$dummy2='DuMMyTExt'; +echo strtolower($dummy2); + +echo '
'; +print '
--------------------< String Substring >--------------------
'; +$subs='Substringme'; +echo substr($subs, 9); +?> \ No newline at end of file diff --git a/types.php b/types.php index fd6ae66..aaf3730 100644 --- a/types.php +++ b/types.php @@ -43,8 +43,13 @@ print '
'; print "
--- [ Object ] ---
"; +class abc { +} +$date = new DateTime(); +$string = new abc; +var_dump($date); print '
'; print "
--- [ Constantes ] ---
"; From 62716bae6d1b6ff0f6cc9937dd0b02e9077e0c2d Mon Sep 17 00:00:00 2001 From: Lokesh Pereiro Date: Sat, 3 Sep 2022 19:13:53 +0200 Subject: [PATCH 5/7] upload finished files --- README.md => functionalities/README.md | 0 arrays.php => functionalities/arrays.php | 0 condicionales.php => functionalities/condicionales.php | 0 dates.php => functionalities/dates.php | 0 dates_traditional.php => functionalities/dates_traditional.php | 0 funciones.php => functionalities/funciones.php | 0 iterators.php => functionalities/iterators.php | 0 math.php => functionalities/math.php | 0 operators.php => functionalities/operators.php | 0 phpinfo.php => functionalities/phpinfo.php | 0 print.php => functionalities/print.php | 0 strings.php => functionalities/strings.php | 0 types.php => functionalities/types.php | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename README.md => functionalities/README.md (100%) rename arrays.php => functionalities/arrays.php (100%) rename condicionales.php => functionalities/condicionales.php (100%) rename dates.php => functionalities/dates.php (100%) rename dates_traditional.php => functionalities/dates_traditional.php (100%) rename funciones.php => functionalities/funciones.php (100%) rename iterators.php => functionalities/iterators.php (100%) rename math.php => functionalities/math.php (100%) rename operators.php => functionalities/operators.php (100%) rename phpinfo.php => functionalities/phpinfo.php (100%) rename print.php => functionalities/print.php (100%) rename strings.php => functionalities/strings.php (100%) rename types.php => functionalities/types.php (100%) diff --git a/README.md b/functionalities/README.md similarity index 100% rename from README.md rename to functionalities/README.md diff --git a/arrays.php b/functionalities/arrays.php similarity index 100% rename from arrays.php rename to functionalities/arrays.php diff --git a/condicionales.php b/functionalities/condicionales.php similarity index 100% rename from condicionales.php rename to functionalities/condicionales.php diff --git a/dates.php b/functionalities/dates.php similarity index 100% rename from dates.php rename to functionalities/dates.php diff --git a/dates_traditional.php b/functionalities/dates_traditional.php similarity index 100% rename from dates_traditional.php rename to functionalities/dates_traditional.php diff --git a/funciones.php b/functionalities/funciones.php similarity index 100% rename from funciones.php rename to functionalities/funciones.php diff --git a/iterators.php b/functionalities/iterators.php similarity index 100% rename from iterators.php rename to functionalities/iterators.php diff --git a/math.php b/functionalities/math.php similarity index 100% rename from math.php rename to functionalities/math.php diff --git a/operators.php b/functionalities/operators.php similarity index 100% rename from operators.php rename to functionalities/operators.php diff --git a/phpinfo.php b/functionalities/phpinfo.php similarity index 100% rename from phpinfo.php rename to functionalities/phpinfo.php diff --git a/print.php b/functionalities/print.php similarity index 100% rename from print.php rename to functionalities/print.php diff --git a/strings.php b/functionalities/strings.php similarity index 100% rename from strings.php rename to functionalities/strings.php diff --git a/types.php b/functionalities/types.php similarity index 100% rename from types.php rename to functionalities/types.php From afb2bd1bcc6f57f22f0006966a93828fbde0c2ad Mon Sep 17 00:00:00 2001 From: Lokesh Pereiro Date: Sat, 3 Sep 2022 19:15:38 +0200 Subject: [PATCH 6/7] upload finished files --- functionalities/README.md => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename functionalities/README.md => README.md (100%) diff --git a/functionalities/README.md b/README.md similarity index 100% rename from functionalities/README.md rename to README.md From 1581e4147d9a0c46f63eb6bd843112e1a54d0eb7 Mon Sep 17 00:00:00 2001 From: Lokesh Pereiro Date: Sun, 4 Sep 2022 13:03:35 +0200 Subject: [PATCH 7/7] Added new Extra folder with extra files --- extraFuncionalities/breakContinues.php | 23 ++++++++++ extraFuncionalities/declaracionEscalar.php | 26 +++++++++++ extraFuncionalities/funcionDie.php | 17 ++++++++ extraFuncionalities/funciones_Arrary.php | 42 ++++++++++++++++++ extraFuncionalities/funciones_String.php | 34 +++++++++++++++ .../include_required/index.php | 19 ++++++++ extraFuncionalities/include_required/ver.php | 16 +++++++ extraFuncionalities/operador_Nave.php | 43 +++++++++++++++++++ extraFuncionalities/returnFunciones.php | 40 +++++++++++++++++ functionalities/math.php | 5 ++- functionalities/types.php | 1 + 11 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 extraFuncionalities/breakContinues.php create mode 100644 extraFuncionalities/declaracionEscalar.php create mode 100644 extraFuncionalities/funcionDie.php create mode 100644 extraFuncionalities/funciones_Arrary.php create mode 100644 extraFuncionalities/funciones_String.php create mode 100644 extraFuncionalities/include_required/index.php create mode 100644 extraFuncionalities/include_required/ver.php create mode 100644 extraFuncionalities/operador_Nave.php create mode 100644 extraFuncionalities/returnFunciones.php diff --git a/extraFuncionalities/breakContinues.php b/extraFuncionalities/breakContinues.php new file mode 100644 index 0000000..0b2cc1b --- /dev/null +++ b/extraFuncionalities/breakContinues.php @@ -0,0 +1,23 @@ +'; +// #Break (Parar el ciclo) +// if($pais == 'Francia'){ +// break; +// } +// } +foreach($paises as $pais){ + #Continue (Evitar un 'ele') + if($pais == 'Chile'){ + continue; + } + echo $pais . '
'; +} +echo '
'; + +?> \ No newline at end of file diff --git a/extraFuncionalities/declaracionEscalar.php b/extraFuncionalities/declaracionEscalar.php new file mode 100644 index 0000000..badb925 --- /dev/null +++ b/extraFuncionalities/declaracionEscalar.php @@ -0,0 +1,26 @@ +
'; +#Esto nos sirve para trabajr con el mismo tipo de datos cuando se trabaja en grupo +#Nos permite evitar que los compareños pases datos en string o cualquier cosa + +## Funcioens del Retorno ## + +function pasarEdad(): int{ + $edad = '20'; + return $edad; +} + +echo pasarEdad(); +#Aqui pasa lo mismo que arriba, pues, cuando se pasa un numero en string te lo convierte en numero. Por eso, tenemos que usar declare(strict_types=1) para evitar que pasen estan cosas. + +?> \ No newline at end of file diff --git a/extraFuncionalities/funcionDie.php b/extraFuncionalities/funcionDie.php new file mode 100644 index 0000000..a32a8b8 --- /dev/null +++ b/extraFuncionalities/funcionDie.php @@ -0,0 +1,17 @@ + + + + + + + + Document + + +

Hola Soy H1

+ + \ No newline at end of file diff --git a/extraFuncionalities/funciones_Arrary.php b/extraFuncionalities/funciones_Arrary.php new file mode 100644 index 0000000..e4b621d --- /dev/null +++ b/extraFuncionalities/funciones_Arrary.php @@ -0,0 +1,42 @@ + 'David','telefono'=>645522991,'pais'=>'Peru', 'edad'=>25]; + +print "
-------- [ extract() ] --------
"; +#Nos permite extraer los elementos de arreglos asociativos como si fueran variables +extract($amigos); +echo $telefono; + +print "
-------- [ array_pop() ] --------
"; +$semana = ['Lunes','Martes','Miercoles', 'Jueves','Viernes','Sabado','Domingo']; +#Nos permite extraer un elemento del array (y guardarlo en una variable) y eliminarlo del dicho array + +$ultimoDia = array_pop($semana); + +foreach($semana as $dia){ + echo $dia.'
'; +} +print '
'; +echo $ultimoDia; + +print '
'; +print "
-------- [ join() ] --------
"; +#Recibe dos paramétros: El 1º puede ser cualquier cosa / 2º nuestro arreglo +#Nos permite evitar tener que ejecutar un ciclo para mostrar los resultados +echo join(' - ', $semana); +// echo join('
', $semana); + +print '
'; +print "
-------- [ count() ] --------
"; + +print '
'; +print "
-------- [ sort() & rsort() ] --------
"; +sort($semana); +echo join(', ', $semana); + +print '
'; +print "
-------- [ array_reverse() ] --------
"; +#Nos permite guardar nuestro arreglo al revés en una variable + +$semanaReverse = array_reverse($semana); +echo join(' *',$semanaReverse); +?> \ No newline at end of file diff --git a/extraFuncionalities/funciones_String.php b/extraFuncionalities/funciones_String.php new file mode 100644 index 0000000..26222a7 --- /dev/null +++ b/extraFuncionalities/funciones_String.php @@ -0,0 +1,34 @@ +-------- [ htmlspecialchars() ] --------
"; +// Nos permite convertir carateres especiales en 'entidades html' +$texto = '<>,&""'; +$texto2 = 'Hola PHP'; +echo htmlspecialchars($texto).'
'; //R: <>,&"" + +// Con esto evitamos que el usuario inyecte otro código o el script. +echo htmlspecialchars($texto2); //R:
<b>Hola PHP</b> + + +print '
'; +print "
-------- [ trim() ] --------
"; +#Nos permite eliminar todos los espacios blancos al principio y al final de una cadena de texto +$string = ' Hola Pueblo '; +$string2 = 'Hola Pueblo'; +// echo $string; +echo trim($string); + +print '
'; +print "
-------- [ strlen() ] --------
"; +echo strlen(trim($string)); + +print '
'; +print "
-------- [ substr() ] --------
"; +echo substr($string2,0,2); //R: Ho +#Devuelve los caracteres de entre la posicion 0 y 2, el resto se corta + +print '
'; +print "
-------- [ strtoupper() & strtolower] --------
"; + +print '
'; +print "
-------- [ strpos() ] --------
"; +?> \ No newline at end of file diff --git a/extraFuncionalities/include_required/index.php b/extraFuncionalities/include_required/index.php new file mode 100644 index 0000000..4d932dd --- /dev/null +++ b/extraFuncionalities/include_required/index.php @@ -0,0 +1,19 @@ + Nos permite que el archivos solo se traiga una vez, con los cual, solo se ejecute una vez en vez de multiples veces por error +include_once 'ver.php'; +// include_once 'ver.php'; +?> \ No newline at end of file diff --git a/extraFuncionalities/include_required/ver.php b/extraFuncionalities/include_required/ver.php new file mode 100644 index 0000000..74ab37a --- /dev/null +++ b/extraFuncionalities/include_required/ver.php @@ -0,0 +1,16 @@ + + + + + + + Include/Required + + +

El resultado de la suma es: +

+ + + \ No newline at end of file diff --git a/extraFuncionalities/operador_Nave.php b/extraFuncionalities/operador_Nave.php new file mode 100644 index 0000000..aa4eebb --- /dev/null +++ b/extraFuncionalities/operador_Nave.php @@ -0,0 +1,43 @@ + 9; +echo '
'; + +echo 10 <=> 10; +echo '
'; + +echo 10 <=> 12; +echo '
'; +echo '
'; + +print '
'; + +$arreglo = [3,45,2,1,-2]; +sort($arreglo); +// Suponiendo que no hay la funcion sort() en php, podemos crear una funcion nosotros mismo para ordenarlos +// function compararF($a,$b){ +// if($a==$b){ +// return 0; +// } elseif($a>$b){ +// return 1; +// } else{ +// return -1; +// } +// } +#Misma funcion en corto + +function compararF($a,$b){ + return $a <=> $b; +} + +// Ahora, el usort() nos permite ordenar nuestro arreglo por la función definida +usort($arreglo, 'compararF'); +echo implode(' - ', $arreglo); +?> \ No newline at end of file diff --git a/extraFuncionalities/returnFunciones.php b/extraFuncionalities/returnFunciones.php new file mode 100644 index 0000000..1070c1e --- /dev/null +++ b/extraFuncionalities/returnFunciones.php @@ -0,0 +1,40 @@ +'; + + +function saludar($nombre){ + return 'Hola: '. $nombre; +} +echo saludar('Lokesh Pereiro'); + + + + + +print '
'; +print "
-------- [ Cálculo Área Triangulo ] --------
"; +#De esta manera tenemos una función que sól se decia a calcular Area (del triangulo); + +function calcularAreaTri($base, $altura){ + $area = ($base * $altura) / 2; + return $area; +} +// echo 'El trinágulo tiene un área de '. calcularAreaTri(10,5). ' metros cuadrados'; + +// Podemos almacenar ese resultado en una variable para que reutilizarlo. +$resultadoAreaTri = calcularAreaTri(10,5); +echo 'El trinágulo tiene un área de '. $resultadoAreaTri. 'm²'; +?> \ No newline at end of file diff --git a/functionalities/math.php b/functionalities/math.php index 0da428f..55adf72 100644 --- a/functionalities/math.php +++ b/functionalities/math.php @@ -1,6 +1,8 @@ '; // Exponentes function: cuadrados, cubos, etc. echo pow(5,2); @@ -63,6 +65,7 @@ function getMinValue($arr){ } return $min; } + echo getMinValue($arr); echo '
'; diff --git a/functionalities/types.php b/functionalities/types.php index aaf3730..7945ad7 100644 --- a/functionalities/types.php +++ b/functionalities/types.php @@ -58,6 +58,7 @@ class abc { // Por lo tanto son únicas y no se puede reescribirlas. Se recomienda escribirlas en mayusculas. define('NOMBRE', 'Lokesh'); define('PI', '3.14'); +// echo M_PI; // define('Nombre', 'Pepe'); echo NOMBRE .'
'; echo PI;