PHP eval() question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Darkside138
    New Member
    • Apr 2008
    • 1

    PHP eval() question

    I'm working on a program that takes a saved variable file and converts it to a string that is structured like a php array. My problem is I need to turn this string into an array in php. Hoping someone can help.

    working example of recursive array: (simplified for easy readability)
    [php]$test = array(blah => value, blah2 => value2, array1 => array(value1 => key1, blah4 => value4),blah3 => value3);
    recursiveArray( $test);
    function recursiveArray( $array) {
    foreach ($array as $key => $value) {
    if (is_array($valu e)) {
    echo $key."<br>";
    recursiveArray( $value);
    } else {
    echo $key." - ".$value."<br>" ;
    }
    }
    }[/php]what I would like to send in is something like this, where the "array" is actually a string:
    [php]$test = eval("array(bla h => value);");[/php]Am I missing something or is there another way to do this?

    Thanks,
    Dave
    Last edited by ronverdonk; Apr 10 '08, 09:41 PM. Reason: code tags!
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    Working...