PHP Classes

File: examples/env.php

Recommend this page to a friend!
  Classes of Christian Vigh   Variable Store   examples/env.php   Download  
File: examples/env.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Variable Store
Store key value pairs in array variables
Author: By
Last change:
Date: 7 years ago
Size: 1,227 bytes
 

Contents

Class file image Download
<?php
   
/****************************************************************************************************

        This example demonstrates how to include environment variables in a VariableStore object.

     ****************************************************************************************************/

   
require_once ( '../Variables.phpclass' ) ;

    if (
php_sapi_name ( ) != 'cli' )
        echo
"<pre>" ;

   
// Initialization values for variables - 3 variables are defined here, 'word1', 'word2' and 'sentence'
    // The 'sentence' variable value references variables 'word1' and 'word2'.
   
$variables =
       [
       
'word1' => 'Hello',
       
'word2' => 'world',
       
'sentence' => '$(word1) $(word2) !'
       
] ;

   
// Initialize our variable store
   
$store = new VariableStore ( $variables, VariableStore::OPTION_DEFAULT | VariableStore::OPTION_USE_ENVIRONMENT_VARIABLES ) ;

   
// Show the contents of our variable store - it should contain the variables 'word1', 'word2', 'sentence' and
    // all the environment variables defined in your session
   
echo "Contents of variable store that includes variables 'word1', 'word2', 'sentence' plus all environment variables :\n" ;
   
print_r ( $store -> ToArray ( ) ) ;