Skip to content

Instantly share code, notes, and snippets.

@sourovroy
Created October 26, 2024 12:12
Show Gist options
  • Save sourovroy/416492a04a13b4fd4076e14315417e79 to your computer and use it in GitHub Desktop.
Save sourovroy/416492a04a13b4fd4076e14315417e79 to your computer and use it in GitHub Desktop.
Basic PHP for WordPress Batch 4
<?php
$abc = "hello";
echo $abc;
function isGreaterThanZero( $a ) {
if ( $a > 0 ) {
echo "TRUE";
} else {
echo "FALSE";
}
}
echo "<br>world<br>";
echo isGreaterThanZero( 4564564646 );
echo "<br>";
echo isGreaterThanZero( -4564564646 );
echo "<br>";
$myArray = array( 1, 2, 3, 4, "Hello", "World" );
for ( $i = 0; $i <= 10; $i = $i + 2 ) {
echo $i;
}
echo "<br>";
$i = 0;
while( $i <= 10 ) {
echo $i;
$i = $i + 2;
}
foreach ( $myArray as $item ) {
echo "<br>";
echo $item;
}
<?php
trait Def {
public $name = "weDevs Academy";
public function __construct() {
echo $this->name;
// echo $this->something3;
}
}
class Xyz {
use Def;
public function get_parents_data() {
return $this->name;
}
}
$new_xyz = new Xyz();
// echo $new_xyz->get_parents_data();
<?php
require_once __DIR__ . '/inheritance.php';
class Abc {
use Def;
public $something = "This is string";
protected $something2 = "This is protected";
private $something3 = "This is private";
private static $something4 = "This is private static property";
public function get_something() {
return self::get_private();
// return $this->something;
// return $this->something;
}
public static function get_private() {
echo self::$something4;
// echo "This from static";
}
}
$new_abc = new Abc();
// $new_abc->get_something();
// echo Abc::get_private();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment