PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.22.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.22.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Support / Arrays.php
Arrays.php
53 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Support;
4
5 /**
6 * Array support.
7 */
8 class Arrays {
9 /**
10 * Flatten an array
11 *
12 * @param array $array Array.
13 *
14 * @return array
15 */
16 public static function flatten( array $array ) {
17 $return = array();
18 array_walk_recursive(
19 $array,
20 function( $a ) use ( &$return ) {
21 $return[] = $a;
22 }
23 );
24 return $return;
25 }
26
27 /**
28 * Insert an array after a key in another array.
29 *
30 * @param string $key Key to insert after.
31 * @param array $source_array Array to insert into.
32 * @param array $insert_array Array to insert.
33 *
34 * @throws \Exception If key does not exist in the array.
35 *
36 * @return array
37 */
38 public static function insertAfter( $key, $source_array, $insert_array ) {
39 $keys = array_keys( $source_array );
40 $index = array_search( $key, $keys );
41
42 if ( false === $index ) {
43 throw new \Exception( "Key $key does not exist in the array" );
44 }
45
46 $pos = $index + 1;
47
48 return array_slice( $source_array, 0, $pos, true ) +
49 $insert_array +
50 array_slice( $source_array, $pos, null, true );
51 }
52 }
53