function pageController()
{
    // Initialize an empty data array.
    $data = [];
    // Add data to be used in the html view.
    $data['message'] = sayHello();
    // Return the completed data array.
    return $data;
}
Exemplo n.º 2
0
<?php

/**
 * Created by PhpStorm.
 * User: jim
 * Date: 2015/11/5
 * Time: 21:30
 */
require 'lib.php';
include 'lib.php';
sayHello();
Exemplo n.º 3
0
<?php

/**
 * Using the require_once keyword we can include external files which contain functions we can then call.
 */
require_once "functions.php";
echo sayHello("Nick");
//=> Hello Nick
echo addNumbers(10, 20);
//=> 30
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Voorbeeld van functie met meerdere parameters</title>
	<link rel="stylesheet" type="text/css" href="http://web-backend.local/css/global.css">
	<link rel="stylesheet" type="text/css" href="http://web-backend.local/css/directory.css">
	<link rel="stylesheet" type="text/css" href="http://web-backend.local/css/facade.css">
</head>

<body class="web-backend-inleiding">

	<section class="body">

		<h1>Voorbeeld van functie zonder parameters</h1>

		<p><?php 
echo sayHello();
?>
</p>


		<h1>Voorbeeld van functie met één parameter</h1>

		<p><?php 
echo sayGoodbye('Peter');
?>
</p>


		<h1>Voorbeeld van functie met meerdere parameters</h1>

		<p><?php 
Exemplo n.º 5
0
// 	echo "hi,$name";
// }
// say();
//默认为值传递
// function sayHello($name){
// 	$name .='1016';
// 	echo "hello,$name";
// }
// $real_name = 'php';
// sayHello($real_name);
// echo '<br />';
// var_dump($real_name);
// //引用传递
// //会触发一个语法错误
// function sayHello($name){
// 	$name .='1016';
// 	echo "hello,$name";
// }
// $real_name = 'php';
// sayHello(& $real_name);
// echo "<br />";
// var_dump($real_name);
function sayHello(&$name)
{
    $name .= '1016';
    echo "hello,{$name}";
}
$real_name = 'PHP';
sayHello($real_name);
echo '<br />';
var_dump($real_name);
Exemplo n.º 6
0
<?php

// Function declaration
/**
 * @param string $name This is the just the first name
 * @param string $location This is the state you live in
 * @param int $age This is how old you are
 */
//use /** to explain your var
function sayHello($name, $location, $age)
{
    return 'Hi ' . $name . ' ' . $location . ' is awesome for a ' . $age . ' years old';
}
$helloString = sayHello('Simon', 'TX', 30);
// Function usage or calling the function = sayHello();
echo $helloString;
/*
 * 1. Create a function that accepts two arguments
 * The first argument is the object to print, make sure its an object
 * The second ___optional___ argument is a title to print on top of the data
 */
/**
 * @param object $data array of your objects
 * @param string $name the title of your objects
 */
function pre($data, $name = null)
{
    // making the second argument optional
    if (!empty($name)) {
        if (php_sapi_name() == 'cli') {
            echo "\n";
Exemplo n.º 7
0
<?php

require_vertx("hello-lib.php");
$eventBus = Vertx::eventBus();
Vertx::logger()->info(sayHello("User"));
/**
 * Test if the require_vertx really loads php files of other module ressources
 * if they are included
 */
$eventBus->registerHandler('test.require_vertx', function ($message) {
    $message->reply(sayHello("Test"));
});
/**
 * test if the Autoclassloader is using the Vertx Classloader to load
 * internal classes
 */
$eventBus->registerHandler('test.autoload.internal', function ($message) {
    $helloObject = new InternalHelloClass("Test");
    $message->reply($helloObject->sayHello());
});
/**
 * test if the Autoclassloader is using the Vertx ClassLoader, so it can find
 * included module classes
 */
$eventBus->registerHandler('test.autoload.external', function ($message) {
    $helloObject = new lib\ExternalHelloClass("Test");
    $message->reply($helloObject->sayHello());
});
Exemplo n.º 8
0
<?php

/**
 * @param string $name This is the just the first name
 * @param string $location This is the state you live in
 * @param int $age This is how old you are
 * @return string
 */
function sayHello($name, $location = 'Austin', $age = 21)
{
    return 'Hi ' . $name . ' ' . $location . ' is awesome for a ' . $age . ' year old';
}
$helloString = sayHello('Samir');
//echo $helloString;
/**
 * @param $data
 * @param null $name
 */
function pre($data, $name = null)
{
    if (!empty($name)) {
        if (php_sapi_name() == 'cli') {
            echo "\n";
            echo "-----------------------------\n";
            echo $name . "\n";
            echo "-----------------------------\n";
        } else {
            echo '<h3>' . $name . '</h3>';
        }
    }
    if (is_object($data) || is_array($data)) {
<?php

/**
 * Say Hello
 *
 * @return string
 */
function sayHello()
{
    // avoid sending output from a function, instead return a value
    return 'Hello';
}
echo '<p>';
// escape output to prevent cross-site scripting (XSS)
echo htmlspecialchars(sayHello());
echo '</p>';
/**
 * Say Hello To
 *
 * @param string $person
 * @return string
 */
function sayHelloTo($person)
{
    return 'Hello, ' . $person;
}
echo '<p>';
// escape output
echo htmlspecialchars(sayHelloTo('Bradley'));
echo '</p>';
echo '<p>';
 public static function usingSayHello($name)
 {
     sayHello($name);
 }
Exemplo n.º 11
0
            $type = "Модератор";
            $st = "color:blue;font-size:22px";
            break;
        default:
            $type = "Прохожий";
            $st = "color:black;font-size:10px";
            break;
    }
    echo "<p style={$st}>Hello {$type} {$name}</p> ";
    //global $w;
    $GLOBALS['w'] = "Changed";
}
print_r($GLOBALS);
//sayHello();
$w = "John";
sayHello($w, 1);
echo $w . "<br>";
//sayHello("Maria",8);
function foo1()
{
    echo "Работает функция" . __FUNCTION__ . "<br>";
    function foo2()
    {
        echo "Работает функция" . __FUNCTION__ . "<br>";
    }
}
foo1();
foo2();
//foo1();
$flag = true;
if ($flag) {
Exemplo n.º 12
0
<?php

// Welcome to the online interface for KPHP! :)
function sayHello($name = "World")
{
    return "Hello {$name}\n";
}
echo sayHello();
echo sayHello("User");
Exemplo n.º 13
0
<?php

/**
 * @param string $name This is just the first name
 * @param string $location This is the state you live in
 * @param int $age This is how old you are
 */
function sayHello($name, $location, $age)
{
    return 'Hi ' . $name . ' ' . $location . ' is awesome for a ' . $age . ' year old';
}
$helloString = sayHello('Samir', 'MD', 31);
echo $helloString;
/*
 * 1. Create a function that accepts two arguments
 * The first argument is the object to print, make sure its an object
 * The second argument is a title to print on top of the data
 */
/**
 * @param $data
 * @param null $name
 */
function pre($data, $name = null)
{
    if (!empty($name)) {
        if (php_sapi_name() == 'cli') {
            echo "----------------------------\n";
            echo $name . "\n";
            echo "----------------------------\n";
        } else {
            echo "<h3>{$name}</h3>";
Exemplo n.º 14
0
<?php

function printWelcome()
{
    echo "<h1>Welcome to our website</h1>";
    echo "<p>Please enjoy the dynamic content</p>";
}
printWelcome();
function sayHello($name, $greeting = "Hello there")
{
    echo "<h1>Welcome to {$name}</h1>";
    echo "<p>{$greeting}</p>";
}
sayHello("Brian the dog", "Who's a good boy then?");
sayHello("Mike");
function addValues($valA, $valB)
{
    $answer = $valA + $valB;
    return $answer;
}
echo "The answer to 4 + 2 is " . addValues(4, 2) . "<br>";
$answer = addValues(100, 50) * 10;
echo "Asnwer is {$answer}<br>";
// puzzle
$users = "Bob, Mary, Peter,Jane,Sue ,Mike ,  Greeta ";
// make array of names
$userList = explode(",", $users);
// tidy up array and remove white space
foreach ($userList as $index => $user) {
    $userList[$index] = trim($user);
}
Exemplo n.º 15
0
</form>

<?php 
//$_GET; // when you want to get things from the URL
//
//$_POST; // when you want to get things from a form that was submitted
//
//$_REQUEST; // when you want to get either of those things
// Collect the user input
//if (isset($_POST['firstName'])) {
//    $enteredName = $_POST['firstName'];
//} else {
//    $enteredName = ' nobody';
//}
// ternary
$enteredName = isset($_POST['firstName']) ? $_POST['firstName'] : null;
// Pass it into the function i.e. call the function
$functionOutput = sayHello($enteredName);
// Collect the return data from the function
// $functionOutput contains the data from the function
// Output the result from the function
echo '<h3>' . $functionOutput . '</h3>';
/**asd
 * @param string $name This is the name they enter on the FE
 * @see http://www.php-fig.org/
 * @return string
 */
function sayHello($name)
{
    return 'Hello ' . $name;
}
Exemplo n.º 16
0
<?php

require_once "../Utilities/functions.php";
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
header("Access-Control-Allow-Origin: *");
$cmd = getValue("cmd");
if ($cmd == "hello") {
    $response = sayHello();
    header('Content-type: application/json');
    echo json_encode($response);
} else {
    if ($cmd == "time") {
        $response = getTime();
        header('Content-type: application/json');
        echo json_encode($response);
    } else {
        echo "\n  <html>\n    <body>\n      <h1>API</h1>\n      <ul>\n        <li>\n          <h2>Say hello to me</h2>\n\n          <h3>Parameters:</h3>\n          <ul>\n            <li>cmd=hello</li>\n          </ul>\n\n          <h3>Returns:</h3>\n          <p>A hello message</p>\n\n          <h3>Example:</h3>\n          <p><a href='hello.php?cmd=hello'>cmd=hello</a></p>\n          <pre>\n            Hello it is nice to meet you.\n          </pre>\n        </li>\n        <li>\n          <h2>Get the time</h2>\n\n          <h3>Parameters:</h3>\n          <ul>\n            <li>cmd=time</li>\n          </ul>\n\n          <h3>Returns:</h3>\n          <p>The current time of day</p>\n\n          <h3>Example:</h3>\n          <p><a href='hello.php?cmd=time'>cmd=time</a></p>\n          <pre>\n            12:15:32\n          </pre>\n        </li>\n      </ul>\n    </body>\n  </html>\n  ";
    }
}
function sayHello()
{
    $response = "Hello it is nice to meet you.";
    return $response;
}
function getTime()
{
    $response = date("h:i:sa");
    return $response;
}
Exemplo n.º 17
0
    echo 'Hello PHP' . '<br>';
    echo 'Hello World' . '<br>';
}
//	调用
traceHelloPHP();
//	回调函数
$func = 'traceHelloPHP';
$func();
echo '<hr>';
//	参数与字符串连接
function sayHello($name)
{
    echo 'Hello ' . $name . '<br>';
}
sayHello('张三');
sayHello('李四');
echo '<hr>';
//	多参数
function traceNum($a, $b)
{
    //	连接形式
    echo 'a = ' . $a . ' ,b = ' . $b . '<br>';
    // 直接调用参数
    echo "a = {$a} ,b = {$b}<br>";
}
traceNum(12, 5);
echo '<hr>';
//	返回值
function add($a, $b)
{
    echo "{$a} + {$b} = ";
Exemplo n.º 18
0
<!DOCTYPE html>
<html>
<head>
    <title>functions</title>
</head>
<body>
    <p>Code to say hello to Fred by default but recieve dynamic variable</p>
    <?php 
function sayHello($name = "Fred")
{
    return sprintf("Hi, there %s", $name);
}
echo sayHello();
echo sayHello("Nev");
?>
    <hr />
    <p>function to apply pre tags around print_r</p>
    <?php 
$arr = array('name' => 'nev', 'age' => '41', 'occupation' => 'web dev');
function prettyp($obj)
{
    echo "<pre>";
    print_r($obj);
    echo "</pre>";
}
prettyp($arr);
?>
    <hr />
    <p>Array pluck </p>
    <?php 
$people = array(array('name' => 'nev', 'age' => '41', 'occupation' => 'web dev'), array('name' => 'clare', 'age' => '36', 'occupation' => 'events'), array('name' => 'fred', 'age' => '0', 'occupation' => 'being cute'));
Exemplo n.º 19
0
<?php

function sayHello($name)
{
    echo 'hello,' . $name;
}
sayHello('Jim');
echo '<hr />';
//可变函数
function sayHello1($name)
{
    echo 'hello,' . $name;
}
$fun_say = 'sayHello1';
$fun_say('Tome');
//匿名函数(必包函数)
$sayHi = function ($name) {
    echo 'hi' . $name;
};
var_dump($sayHi);
echo '<hr />';
$sayHi('PHP');
Exemplo n.º 20
0
<?php

/**
 *  Hello world demo
 */
function sayHello($name = 'World')
{
    printf('Hello %s !', $name);
}
sayHello();
echo PHP_EOL;
sayHello('Paris');