0
 //below example now works thanks to Alexander. 

I am trying to use array_walk_recursive, and I can't get the original value in the array to change. What exactly am I doing wrong here?

public function setConstants()
{
    array_walk_recursive($this->_arr, function(&$item, $key2){

        $constants = get_defined_constants(true);

        foreach($constants["user"] as $key => $value)
        {
            if (strstr($item, $key)){
                $item = str_replace($key,$value,&$item); //EDITED FOR VALIDITY, WORKS.
            }
        }
    });
    return $this->_arr;
}

I am trying to traverse the multidemensional array "_arr" using array_walk_recursive, and for every constant thats part of constants[user] (which is an array as well) i want to replace the equivalent value in _arr if the string matches the constant name

2
  • 1
    What exactly you want to do? explain in example Commented Feb 17, 2012 at 20:00
  • i explained it, but Alexander got what I meant :) thanks anyway! Commented Feb 17, 2012 at 20:04

1 Answer 1

2

I think you are not assigning the replaced value appropriately.

$item = str_replace($key,$value,$item);

Instead of:

str_replace($key,$value,&$item);

Should be enough.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.