| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Core; |
| 4 |
|
| 5 |
defined('ABSPATH') || exit; |
| 6 |
|
| 7 |
class Helper |
| 8 |
{ |
| 9 |
public function input($input = '', $old_data = null) |
| 10 |
{ |
| 11 |
if (!$old_data) { |
| 12 |
$old_data = $_POST; |
| 13 |
} |
| 14 |
$value = $this->avalue_dot($input, $old_data); |
| 15 |
if ($value) { |
| 16 |
return $value; |
| 17 |
} |
| 18 |
return ''; |
| 19 |
} |
| 20 |
|
| 21 |
public function array_get($key = null, $array = array(), $default = false) |
| 22 |
{ |
| 23 |
return $this->avalue_dot($key, $array, $default); |
| 24 |
} |
| 25 |
|
| 26 |
public function avalue_dot($key = null, $array = array(), $default = false) |
| 27 |
{ |
| 28 |
$array = (array)$array; |
| 29 |
if (!$key || !count($array)) { |
| 30 |
return $default; |
| 31 |
} |
| 32 |
$option_key_array = explode('.', $key); |
| 33 |
|
| 34 |
$value = $array; |
| 35 |
|
| 36 |
foreach ($option_key_array as $dotKey) { |
| 37 |
if (isset($value[$dotKey])) { |
| 38 |
$value = $value[$dotKey]; |
| 39 |
} else { |
| 40 |
return $default; |
| 41 |
} |
| 42 |
} |
| 43 |
return $value; |
| 44 |
} |
| 45 |
} |
| 46 |
|