default value and existence of index checking.
I not a huge change, its a good change and very handy.
<?php$post = array(
'user' => array(
'basicInformation' => array(
'name' => 'Mathias',
'surname' => 'Grimm'
),
));
// normal php way$sName =
isset($post['user']['basicInformation']['name' ]) ?
$post['user']['basicInformation']['name' ] : null;$sSurname =
isset($post['user']['basicInformation']['surname']) ?
$post['user']['basicInformation']['surname'] : null;
// default value$sLocale = isset($post['user']['locale']) ?
$post['user']['locale'] : 'Europe/Dublin';
// ===================================================================
// ArrayPath$sName = ArrayPath::get('user/basicInformation/name'
, $post);$sSurname = ArrayPath::get('user/basicInformation/surname' ,
$post);
// with default value$sLocale = ArrayPath::get('user/locale', $post,
'Europe/Dublin');
On Tue, Oct 7, 2014 at 5:12 PM, Florian Margaine <[email protected]>
wrote:
> Hi!
>
> How is it better than:
>
> $idx3 = $_POST['idx1']['idx2']['idx3'];
>
> ?
>
> Regards,
> Florian Margaine
> Le 7 oct. 2014 18:05, "Mathias Grimm" <[email protected]> a écrit :
>
> Hi,
>> I would like to suggest something for php like a class I am using
>>
>> https://github.com/mathiasgrimm/arraypath
>>
>> The reason is to access arrays like this:
>>
>> $idx3 = ArrayPath::get('idx1/idx2/idx3', $_POST, 'myDefaultValue');
>>
>>
>> Regards,
>> Mathias
>>
>