I am attempting to take a string:

"photos:0:0:ref"

and turn this into a multi-dimensional array:

$arrayName[photos][0][0][ref]

I've been looking all over for something to help me with us, and alas, no luck.

Any suggestions?

Thank you,

Mateo Nares

    easy - you split the string into a temp array, and use that to index the new array

    $string = "photos:0:0:ref";
    $temp = explode(":", $string);
    $arrayName[$temp[0]][$temp[1]][$temp[2]][$temp[3]] = "";
    //this is the same as doing
    //$arrayName["photos"]["0"]["0"]["ref"] = "";
    

    adam

      This is great, but what if I don't know ahead of time what the string will be...I need to do this dynanically, such that

      "photos:0:0:ref" will be $arrayName[photos][0][0][ref]

      but

      "parts:0:typeOfPart" will yield $arrayName[parts][0][typeOfPart]

      employing the same method to generate both.

        yeah i only put the string in to illustrate the point - as long as you have a variable in there, it will work. and just adapt the code for the next bit, when you only have three parts

          Thank you very much. I'll use that, then.

          Mateo

            Write a Reply...