This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class EntityDecorator. | |
*/ | |
class EntityDecorator { | |
protected $entity; | |
protected $wrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fun1(Callable $func) | |
{ | |
$func(); | |
return "This function is "; | |
} | |
class Sample | |
{ | |
public function __invoke() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function myfun($num1, $num2, $ctr = 1) | |
{ | |
for ($i = $num1; $i <= $num2; $i += $ctr) | |
{ | |
yield $i; | |
} | |
} | |
echo 'Odd numbers: '; | |
foreach (myfun(1, 7, 2) as $num) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$myBooks = array( | |
array( | |
"title" => "The Grapes of Wrath", | |
"author" => "John Steinbeck", | |
"pubYear" => 1939 | |
), | |
array( | |
"title" => "Travels With Charley", | |
"author" => "John Steinbeck", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$make = array( "Chevrolet", "Ford", "Dodge", "Cadillac", "Chevrolet" ); | |
$model = array( "Malibu", "Focus", "Ram", "Escalade", "Corvette" ); | |
$year = array( 2010, 2011, 2012, 2013, 2014 ); | |
array_multisort( $authors, $titles, $pubYears ); | |
// Displays "Array ( [0] => Cadillac [1] => Chevrolet [2] => Chevrolet [3] => Dodge [4] => Ford )" | |
print_r ( $make ); | |
echo "<br/>"; | |
// Displays "Array ( [0] => Escalade [1] => Corvette [2] => Malibu [3] => Ram [4] => Focus )" | |
print_r ( $model ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$make = array( "Chevrolet", "Ford", "Dodge", "Cadillac" ); | |
$model = array( "Malibu", "Focus", "Ram", "Escalade" ); | |
$year = array( 2010, 2011, 2012, 2013 ); | |
array_multisort( $authors, $titles, $pubYears ); | |
// Displays "Array ( [0] => Cadillac [1] => Chevrolet [2] => Dodge [3] => Ford )" | |
print_r ( $make ); | |
echo "<br/>"; | |
// Displays "Array ( [0] => Escalade [1] => Malibu [2] => Ram [3] => Focus )" | |
print_r ( $model ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Object with an array inside | |
$object->array['value']['value']; | |
//Array with an object | |
$array['object']->value; | |
//Accessing a property of an object | |
$object->value; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Code for the Bing News feature. | |
*/ | |
include_once 'bing_news.features.inc'; | |
define ('BING_NEWS_URL', 'https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27news%27&Query=%27@bing_news_query%27&NewsSortBy=%27Date%27&@bing_skip&$format=json'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Load instance of entity | |
$node = entity_create('node', array('type' => 'content_type')); | |
$entity = entity_metadata_wrapper('node',$node); | |
//Set properties | |
$entity->author = $user->uid; // Author | |
$entity->title->set("String"); //Title | |
$entity->field_name->set("String"); //Textfield | |
$entity->body->set(array('value' => "String or HTML")); //Body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//module_invoke('module_name', 'block_view', 'block_identifier') | |
//Printing using Drupal block system | |
$block = module_invoke('block', 'block_view', '1'); | |
print render($block['content']); | |
//Printing using a contrib module block, this example uses the weather module | |
$block = module_invoke('weather', 'block_view', 'user'); | |
print render($block['content']); |