Skip to content

Instantly share code, notes, and snippets.

@Mombuyish
Last active April 14, 2018 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mombuyish/a5fe6024d0bb9bf91c99102422ab55c1 to your computer and use it in GitHub Desktop.
Save Mombuyish/a5fe6024d0bb9bf91c99102422ab55c1 to your computer and use it in GitHub Desktop.
<?php
$array = ['albums' => ['rock' => ['count' => 75]]];
$count = data_get($array, 'albums.rock.count'); // 75
$avgCost = data_get($array, 'albums.rock.avg_cost', 0); // 0
$object->albums->rock->count = 75;
$count = data_get($object, 'albums.rock.count'); // 75
$avgCost = data_get($object, 'albums.rock.avg_cost', 0); // 0
//wildcard
$array = ['albums' => ['rock' => ['count' => 75], 'punk' => ['count' => 12]]];
$counts = data_get($array, 'albums.*.count'); // [75, 12]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment