Re: Funny array function
| From: | kuldeep dhaka | Date: | Sun, 30 Sep 2012 12:05:36 +0000 |
| Subject: | Re: Funny array function | ||
| References: | 1 2 | Groups: | php.internals php.qa |
| Request: | Send a blank email to internals+get-63251@lists.php.net to get a copy of this message | ||
i m extending the wordpress internal widget input api to simplify things,
so for that i wanted a function that perform drill.
i have considered other options but they wont be effecient, if a php
internal function is build it would be just a [] similar one, and most
effecient
because while recursing through the function.
i built a drill function
function array_drill( $array, $key){
foreach( $key as $k ){
if( isset( $array[$k] ) )
$array = $array[$k];
else
return false;
}
return $array;
}
just convert [] to function drill
On Sun, Sep 30, 2012 at 5:26 PM, Charlie Somerville <
charlie@charliesomerville.com> wrote:
> I'm struggling to imagine how such a function would be useful considering
> you can already use [] to index arrays.
>
> If you have a variable 'depth' you need to drill down to, then writing a
> function to do that is also fairly trivial.
>
> On Sunday, 30 September 2012 at 9:50 PM, kuldeep dhaka wrote:
>
> hello guys,
> this is my first time, if thing mail is at wrong place please forward it
> the right place.
> while coding , i just found a requirement, its little bit funny. if it
> already exists, please be calm and mail me the function name and its usage.
>
> for accessing arrays we use
> <?php
> echo $array["school"]["class"]["roll_number"]["name"];
> // this will print
> the name of the student
> /*
> i was thinking if is their any function that can do the above work like
> */
> echo array_drill($array,
> array("school","class","roll_number","name"));
>
> // like wise while assigning values
> array_drill(<array to perform on>, <keys>, <new value>);
> ?>
> i hope you guys would have understood what i mean.
> kuldeep singh dhaka
> kuldeepdhaka9@gmail.com
>
>
>