The html->tagValue function is useful for pulling a specific value out
of the data array based on a path string.  But why is this limited to
the data array and why is it limited to only 2 level deep.  Is there a
PHP function that would allow me to pull a specific value from an
arbitrary array based on a delimited string.  For example.  Say $arr is
an array and I need the value $arr['key1']['key2']['key3']['key4'].  I
wrote a simple function that allows me to pull that value by calling
getValue('key1/key2/key3/key4'). It may appears at first seem to be
useless but there are places where this is desirable.

Here is my code:

  function getValue($arr, $tag) {
      if(!is_array($arr)) {
        trigger_error('getValue(): First argument should be an array',
E_USER_WARNING);
      }
      $keys = explode("/", $tag);
      foreach ($keys as $key) {
        if (!array_key_exists($key,$arr)) return null;
        $arr = $arr[$key];
      }
      return $arr;
  }

OK, I guess my questions are...

1) Am I reinventing the wheel.  Is there something in PHP that does
this?
2) Do you think that could be a usefull addition to the cake core?
Where would it belong?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to