28. DEEP VAR INTERPOLATION
$obj = new stdClass();
$obj-some = 'hello';
$obj-foo = new stdClass();
$obj-foo-bar = 123;
echo Value is $obj-some;
//Object of class stdClass could not be converted to string in
echo Value is $obj-foo-bar;
//Value is 123
echo Value is {$obj-foo-bar};
//Same for array
$ar = array('some' = 'var');
echo Value is $ar['some']; //syntax error
echo Value is {$ar['some']}; //Value is var
28
71. AUTO_PREPEND_FILE
php.ini
auto_prepend_file string
Specifies the name of a file that is automatically parsed before the
main file. The file is included as if it was called with the
require()function, so include_path is used.
The special value none disables auto-prepending.
71
72. AUTO_PREPEND_FILE
php.ini
auto_prepend_file string
Specifies the name of a file that is automatically parsed before the
main file. The file is included as if it was called with the
require()function, so include_path is used.
The special value none disables auto-prepending.
Greatplaceforyourawesomemydie,dump,
debug,pukeetc.functions.
Butbecarefulwhendeploying.
72
77. FILE INCLUDE
BTW. T HIS A LSO W ORKS
//function.php
return function($data) {
print_r($data);die();
};
//index.php
$dump = include 'function.php';
$dump(array(hello, 'moto'));
77
93. RANDOM ARRAY ITEM
$data = array(
'foo' = 123,
'bar' = 1987,
'wee' = 'ugh'
);
// not like that - works only for number indexed arrays
without gaps !
$random = $data[rand(0, count($data) - 1)];
// or that way - array_rand returns key, not value!
$random = array_rand($data);
// that way - works always
$random = $data[array_rand($data)];
93
95. MULTIPLE VALUE CHECK
$person = 'Barney';
if ($person == 'Joey' || $person == 'Rachel' || $person == 'Ross'
|| $person == 'Phoebe' || $person == 'Monica' || $person == 'Chandler'
) {
echo 'Best comedy show ever';
} else if ($person == 'Barney' || $person == 'Ted'
|| $person == 'Lily' || $person == 'Marshal'
|| $person == 'Robin'
) {
echo 'Copy of best comedy show ever, but still good one';
} else {
echo 'Maybe another good show';
}
95
96. MULTIPLE VALUE CHECK
$person = 'Barney';
switch ($person) {
case 'Joey':
case 'Rachel':
case 'Ross':
/* ... */
echo 'Best comedy show ever';
break;
case 'Barney';
case 'Ted';
/* ... */
echo 'Like a copy of best show ever, but still good one';
break;
default:
echo 'Maybe another good show';
}
96
97. MULTIPLE VALUE CHECK
$person = 'Barney';
if (in_array($person, array('Joey', 'Rachel', 'Ross', 'Phoebe', 'Monica',
'Chandler')))
) {
echo 'Best comedy show ever';
} else if (in_array($person, array('Barney', 'Ted', 'Lily', 'Marshal',
'Robin')))
) {
echo 'Like a copy of best comedy show ever, but still good one';
} else {
echo 'Maybe another good show';
}
97
98. MULTIPLE VALUE CHECK
BTW!
in_array($needle, $haystack) works like '=='
in_array($needle, $haystack, true) works like '==='
98
115. $var = 'a';
for($i = 0; $i 150; $i++) {
$var++;
echo $var, ' ';
}
//output?
//b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag ah
ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb bc bd be bf bg
bh bi bj bk bl bm bn bo bp bq br bs bt bu bv bw bx by bz ca cb cc cd ce cf
cg ch ci cj ck cl cm cn co cp cq cr cs ct cu cv cw cx cy cz da db dc dd de
df dg dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz ea eb ec ed
ee ef eg eh ei ej ek el em en eo ep eq er es et eu
115