Re: ArrayPath

From: Date: Tue, 07 Oct 2014 16:14:37 +0000
Subject: Re: ArrayPath
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-77805@lists.php.net to get a copy of this message
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 >> >

« previous php.internals (#77805) next »