how to make a array path

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

how to make a array path

skank
first thank for all CakePHP. I learned a lot of thing when i work with your framework and I hope I can be useful one day

I am writing this little code to cycle through the array and I think that it can be useful

<?php

function set($path,$value,&$point){
    $aPath
= explode('.',$path);
   
if(count($aPath)>1){
        $path
= strstr($path,'.');
        $path
= substr($path,-strlen($path)+1);
       
if( !isset($point[$aPath[0]]) || !is_array($point[$aPath[0]])){
            $point
[$aPath[0]] = [];
       
}
       
return set($path,$value,$point[$aPath[0]]);
   
}else{
        $point
[$aPath[0]] = $value;
   
}
   
return true;
}

//test
$myArray
= [];
set('foo.bar','it works',$myArray);
set('foo.foo',['bar' =>'it works'],$myArray);
set('a.b.c.d.e.f','it works',$myArray);
var_dump
($myArray);



--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.