Is it possible to do something like this in PHP?
$index1 = "[0][1][2]";
$index2 = "['cat']['cow']['dog']";
// I want this to be $myArray[0][1][2]
$myArray{$index1} = 'stuff';
// I want this to be $myArray['cat']['cow']['dog']
$myArray{$index2} = 'morestuff';
I’ve searched for a solution, but I don’t think I know the keywords involved in figuring this out.
Not directly.
$myArray[$index]would evaluate to$myArray['[0][1][2]']. You would probably have to separate each dimension or write a little function to interpret the string:You can probably find some regular expression to more easily extract the indices which would lead to something like:
To set a value in the array the following function could be used:
Note: I made above code in the answer editor so it may contain a typo or two ; )