php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #31058 array_change_key_case recursive option
Submitted: 2004-12-10 21:53 UTC Modified: 2010-09-24 10:27 UTC
Votes:7
Avg. Score:4.1 ± 1.1
Reproduced:7 of 7 (100.0%)
Same Version:4 (57.1%)
Same OS:5 (71.4%)
From: veeeee at gmail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 5.0.2 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-12-10 21:53 UTC] veeeee at gmail dot com
Description:
------------
It would be quite handy were there an option (optional 3rd parameter) to array_change_key_case so that it would recurse into multi-dimensional arrays so one would not need to create work arounds such as:

function ack_r($array, $case) 
{
  $array = array_change_key_case($array, $case);
  foreach ($array as $key => $value) {
    if ( is_array($value) ) {
      $array[$key] = ack_r($value, $case);
    }
  }
  return $array;
}





Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-24 10:27 UTC] aharvey@php.net
-Package: Feature/Change Request +Package: *General Issues
 [2010-09-24 10:27 UTC] aharvey@php.net
Re-requested in request #52917.
 [2010-09-24 17:52 UTC] luis dot pessoa67 at ibest dot com dot br
another way to do it:

    function ack_r3(&$array, $case=CASE_LOWER, $flag_rec=false) 
    {
      $array = array_change_key_case($array, $case);
      if ( $flag_rec ) {
        foreach ($array as $key => $value) {
            if ( is_array($value) ) {
                ack_r3($array[$key], $case, true);
            }
        }
      }
    }

note that: ack_r3($array, $case, false) <=> array_change_key_case($array, $case)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC