File tree Expand file tree Collapse file tree 2 files changed +18
-41
lines changed Expand file tree Collapse file tree 2 files changed +18
-41
lines changed Original file line number Diff line number Diff line change @@ -512,56 +512,33 @@ Keys from the `$order` array which do not exist in the original array will be ig
512512```
513513use Bayfront\ArrayHelpers\Arr;
514514
515- $person = [
516- 'address' => [
517- 'street' => '123 Main St.',
518- 'state' => 'IL',
519- 'zip' => '60007',
520- 'city' => 'Chicago'
521- ],
522- 'id' => 12345,
523- 'active' => true,
524- 'name' => [
525- 'last' => 'Doe',
526- 'first' => 'John'
527- ]
515+ $address = [
516+ 'street' => '123 Main St.',
517+ 'state' => 'IL',
518+ 'zip' => '60007',
519+ 'city' => 'Chicago'
528520];
529521
530522$order = [
531- 'id',
532- 'name.first',
533- 'name.last',
534- 'address.street',
535- 'address.city',
536- 'address.state',
537- 'address.zip',
538- 'active'
523+ 'street',
524+ 'city',
525+ 'state',
526+ 'zip',
527+ 'country'
539528];
540529
541- $person = Arr::order($person , $order);
530+ $address = Arr::order($address , $order);
542531```
543532
544533The above example will return the following array:
545534
546535```
547536Array
548537(
549- [id] => 12345
550- [name] => Array
551- (
552- [first] => John
553- [last] => Doe
554- )
555-
556- [address] => Array
557- (
558- [street] => 123 Main St.
559- [city] => Chicago
560- [state] => IL
561- [zip] => 60007
562- )
563-
564- [active] => 1
538+ [street] => 123 Main St.
539+ [city] => Chicago
540+ [state] => IL
541+ [zip] => 60007
565542)
566543```
567544
Original file line number Diff line number Diff line change @@ -359,19 +359,19 @@ public static function renameKeys(array $array, array $keys): array
359359 }
360360
361361 /**
362- * Order an array based on an array of keys in dot notation .
362+ * Order an array based on an array of keys.
363363 *
364364 * Keys from the $order array which do not exist in the original array will be ignored.
365365 *
366366 * @param array $array (Original array)
367- * @param array $order (Array of keys in dot notation in the order to be returned)
367+ * @param array $order (Array of keys in the order to be returned)
368368 *
369369 * @return array
370370 */
371371
372372 public static function order (array $ array , array $ order ): array
373373 {
374- return self ::undot ( self :: only (array_replace (array_flip ($ order ), self :: dot ( $ array )) , array_keys (self :: dot ( $ array)) ));
374+ return self ::only (array_replace (array_flip ($ order ), $ array ), array_keys ($ array ));
375375 }
376376
377377 /**
You can’t perform that action at this time.
0 commit comments