1 | <?php |
||
19 | class LdapUtils |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Converts a string distinguished name into its separate pieces. |
||
24 | * |
||
25 | * @param string $dn |
||
26 | * @param int $withAttributes Set to 0 to get the attribute names along with the value. |
||
27 | * @return array |
||
28 | */ |
||
29 | public static function explodeDn($dn, $withAttributes = 1) |
||
39 | |||
40 | /** |
||
41 | * Given a DN as an array in ['cn=Name', 'ou=Employees', 'dc=example', 'dc=com'] form, return it as its string |
||
42 | * representation that is safe to pass back to a query or to save back to LDAP for a DN. |
||
43 | * |
||
44 | * @param array $dn |
||
45 | * @return string |
||
46 | */ |
||
47 | public static function implodeDn(array $dn) |
||
59 | |||
60 | /** |
||
61 | * Given a full escaped DN return the RDN in escaped form. |
||
62 | * |
||
63 | * @param string $dn |
||
64 | * @return string |
||
65 | */ |
||
66 | public static function getRdnFromDn($dn) |
||
73 | |||
74 | /** |
||
75 | * Recursively implodes an array with optional key inclusion |
||
76 | * |
||
77 | * Example of $include_keys output: key, value, key, value, key, value |
||
78 | * |
||
79 | * @access public |
||
80 | * @param array $array multi-dimensional array to recursively implode |
||
81 | * @param string $glue value that glues elements together |
||
82 | * @param bool $include_keys include keys before their values |
||
83 | * @param bool $trim_all trim ALL whitespace from string |
||
84 | * @return string imploded array |
||
85 | */ |
||
86 | public static function recursive_implode(array $array, $glue = ',', $include_keys = false, $trim_all = true) |
||
105 | |||
106 | } |
||
107 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.