Skip to content

Instantly share code, notes, and snippets.

@angch
Last active August 19, 2016 11:23
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 angch/87957672a84589e2537cbaf49e126a99 to your computer and use it in GitHub Desktop.
Save angch/87957672a84589e2537cbaf49e126a99 to your computer and use it in GitHub Desktop.
<?php
$transaction = [
'id' => 1795,
'case_number' => 'TX2015-0123',
'property' => [
'id' => 69134,
'propertyType' => [
'id' => 1,
'name' => 'Residential'
],
'address' => [
'block' => '160',
'street' => 'Paya Lebar Road',
'subpremise' => '#07-05',
'building' => 'Orion Industrial Building',
'country_code' => 'SG'
],
'askingPrice' => '2500000.00',
'photos' => [
[
'url' => 'https://www.prosage.com/thumbnails/600x400F/1c93ad90-639b-4dlc-988b-b98f75364db0.jpg',
'is_default' => 1
],
[
'url' => 'https://www.prosage.com/thumbnails/600x400F/8de99fb6-9545-4f5f-8dfc-235a57a2b8c1.jpg',
'is_default' => 0
],
[
'url' => 'https://www.prosage.com/thumbnails/600x400F/e595918f-8b22-4250-9b29-72c1d3f5dc45.jpg',
'is_default' => 0
]
]
],
];
function getValueByPath($array, $keys)
{
// screw you, php is not javascript, stop traversing structures with "."
$ks = explode(".", $keys);
$v = $array;
while (sizeof($ks)>0) {
$k = array_shift($ks);
if (is_array($v) && isset($v[$k])) {
$v = $v[$k];
} else {
throw new Exception("No such index ".$k);
}
}
return $v;
}
print_r(getValueByPath($transaction, 'property.photos.0.url'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment