Skip to content

Instantly share code, notes, and snippets.

@synsa
Forked from smasty/01.php
Created May 31, 2022 18:29
Show Gist options
  • Save synsa/32b31114f3d13e5ae9a60dc46b9d9c4f to your computer and use it in GitHub Desktop.
Save synsa/32b31114f3d13e5ae9a60dc46b9d9c4f to your computer and use it in GitHub Desktop.
10 PHP One Liners to Impress Your Friends - http://smasty.net/blog/10-php-oneliners
<? foreach(range(1, 10) as $i) echo $i * 2 . " ";
<? echo array_sum(range(1, 1000));
<?
$words = array("php", "foo", "framework", "apache", "nginx");
$tweet = "This is an example tweet talking about PHP and Apache.";
foreach($words as $word) if(stripos($tweet, $word) !== false) echo "$word\n";
<? echo file_get_contents("oneliners.php");
<? foreach(range(1, 4) as $i) echo "Happy Birthday " .($i == 3 ? "dear Martin" : "to You") . "\n";
<? foreach(array(49, 58, 76, 82, 88, 90) as $i) $i > 60 ? ($passed[] = $i) : ($failed[] = $i);
<? echo simplexml_load_file("http://search.twitter.com/search.atom?q=php")->asXML();
<?
echo min(array(14, 35, -7, 46, 98)) . "\n";
echo max(array(14, 35, -7, 46, 98)) . "\n";
<? ($pid = pcntl_fork()) == -1 ? exit(1) : ($pid ? hardCoreAction() && pcntl_wait($status) : hardCoreAction());
<?
// The idea by @tvlooy
// and a small bug fix by me.
foreach($p = range(2, 100) as $v) foreach(range(2, $v - 1) as $c) if(!($v % $c) && $v != 2) unset($p[$v - 2]);
echo join("\n", $p);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment