Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ejemplos random en php
<?php
$palabra = "asdasdasdasdasdasd";
$result = explode('a', $palabra);
$palabra = implode('a', $result);
var_dump($palabra);
~
<?php
$f = fopen("test.txt", 'r');
fgets($f);
$contador = 0;
while ( $line = fgets($f) ) {
$line = trim($line);
$columns = explode("\t", $line);
if ( is_numeric($columns[1]) )
$contador += intval($columns[1]);
else {
echo "Me fui a la chucha";
echo $columns[1];
exit(1);
}
}
fclose($f);
<?php
$i = 1;
while ( $i <= 6) {
echo "hola\n";
$i += 2;
}
<?php
$f = fopen($argv[1], 'r');
fgets($f);
while ( $l = fgets($f) ) {
echo trim($l);
}
fclose($f);
<?php
$valor2 = ($valor = 2);
var_dump($valor);
var_dump($valor2);
<?php
$valor2 = ($valor = 2);
var_dump($valor);
var_dump($valor2);
<?php
$suma = 0;
for ( $vez_actual = 1 ; $vez_actual <= 3 ; $vez_actual += 1 ) {
$suma += $vez_actual;
}
var_dump($suma);
<?php
$m = [
[1,2,3,4],
[3,4,3,1],
[3,4,5,6]
];
$largo = 4;
$contadores = array_fill(1, $largo - 1, 0);
print_r($contadores);
foreach ( $m as $rows ) {
$i = 1;
while ( $i < $largo ) {
$contadores[$i] += $rows[$i];
$i += 1;
}
}
var_dump($contadores);
<?php
$lista = [9,8,'a',[1,2,3],9,9];
foreach ( $lista as $element ) {
echo $element;
}
$size = count($lista);
$i = 0;
while ( $i < $size ) {
print_r($lista[$i]);
$i += 1;
sleep(1);
}
for ( $i = 2 ; $i < 1000 ; $i *= 2 ) {
print_r($i);
echo "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.