PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / libraries / adapter / utilities / array.php

array.php in VikBooking Hotel Booking Engine & PMS trunk, at libraries/adapter/utilities/array.php

87 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikWP - Libraries
4 * @subpackage adapter.html
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2023 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Utility class for doing all sorts of odds and ends with arrays.
16 *
17 * @since 10.1.16
18 */
19 final class ArrayHelper
20 {
21 /**
22 * Private constructor to prevent instantiation of this class.
23 */
24 private function __construct()
25 {
26
27 }
28
29 /**
30 * Utility function to map an array to a string.
31 *
32 * @param array $array The array to map.
33 * @param string $innerGlue The glue (optional, defaults to '=') between the key and the value.
34 * @param string $outerGlue The glue (optional, defaults to ' ') between array elements.
35 * @param boolean $keepOuterKey True if final key should be kept.
36 *
37 * @return string
38 */
39 public static function toString(array $array, $innerGlue = '=', $outerGlue = ' ', $keepOuterKey = false)
40 {
41 $output = array();
42
43 foreach ($array as $key => $item)
44 {
45 if (is_array($item))
46 {
47 if ($keepOuterKey)
48 {
49 $output[] = $key;
50 }
51
52 // This is value is an array, go and do it again!
53 $output[] = static::toString($item, $innerGlue, $outerGlue, $keepOuterKey);
54 }
55 else
56 {
57 $output[] = $key . $innerGlue . '"' . htmlspecialchars($item, ENT_COMPAT, 'UTF-8') . '"';
58 }
59 }
60
61 return implode($outerGlue, $output);
62 }
63
64 /**
65 * Method to determine if an array is an associative array.
66 *
67 * @param array $array An array to test.
68 *
69 * @return boolean
70 */
71 public static function isAssociative($array)
72 {
73 if (is_array($array))
74 {
75 foreach (array_keys($array) as $k => $v)
76 {
77 if ($k !== $v)
78 {
79 return true;
80 }
81 }
82 }
83
84 return false;
85 }
86 }
87