| Conditions | 8 |
| Paths | 7 |
| Total Lines | 22 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 4 | function insert_if_exists ($insert, $template = null, $match = null) { |
||
| 5 | if (!is_null($insert)) { // if item exists |
||
| 6 | if (is_array($insert)) { // if more than one item is given |
||
| 7 | $ret = ''; // total of all items to return |
||
| 8 | foreach ($insert as $in) { // for each item |
||
| 9 | $ret .= insert_if_exists($in, $template, $match); // get the value if it exists |
||
| 10 | } |
||
| 11 | return $ret; // return total |
||
| 12 | } |
||
| 13 | if (!is_null($match) && !$match($insert)) { // if a match function is set and item doesn't match |
||
| 14 | return ''; // return nothing |
||
| 15 | } |
||
| 16 | if (!is_null($template)) { // if a template is set |
||
| 17 | if (is_callable($template)) { // if the template is a function |
||
| 18 | return $template($insert); // insert value into the function |
||
| 19 | } |
||
| 20 | return $template; // use the template as a replacement |
||
| 21 | } |
||
| 22 | return $insert; // else, return the value |
||
| 23 | } |
||
| 24 | return ''; // if item doesn't exist, return nothing |
||
| 25 | } |
||
| 26 | } |