Skip to content

Instantly share code, notes, and snippets.

@duan-li
Last active August 14, 2017 06:30
Show Gist options
  • Save duan-li/cc94c7568757099921c6d98e5eea3129 to your computer and use it in GitHub Desktop.
Save duan-li/cc94c7568757099921c6d98e5eea3129 to your computer and use it in GitHub Desktop.
laravel array help function array_get
<?php
// https://github.com/rappasoft/laravel-helpers
$arr = [
'a' => [
'b' => 'b1',
'c' => 'c1',
],
'd' => [
'd1',
'd2',
'd3',
]
];
echo array_get($arr, 'a.b', 'not exist'); // output b1
echo array_get($arr, 'a.c', 'not exist'); // output c1
echo array_get($arr, 'd.0', 'not exist'); // output d1
echo array_get($arr, 'd.1', 'not exist'); // output d2
echo array_get($arr, 'd.2', 'not exist'); // output d3
die;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment