Re: ArrayPath
| From: | Mathias Grimm | Date: | Tue, 07 Oct 2014 16:19:11 +0000 |
| Subject: | Re: ArrayPath | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-77806@lists.php.net to get a copy of this message | ||
This is handy just for programmers using recommended php.ini settings for
development (error_reporting = E_ALL and display_errors = On).
People using @, display_errors = Off or any other sort of sorcery don't
have such problems.
On Tue, Oct 7, 2014 at 5:14 PM, Mathias Grimm <mathiasgrimm@gmail.com>
wrote:
> 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 <florian@margaine.com>
> wrote:
>
>> Hi!
>>
>> How is it better than:
>>
>> $idx3 = $_POST['idx1']['idx2']['idx3'];
>>
>> ?
>>
>> Regards,
>> Florian Margaine
>> Le 7 oct. 2014 18:05, "Mathias Grimm" <mathiasgrimm@gmail.com> 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
>>>
>>
>