How can 20k strings be efficiently stored in an array with variable depths?

To efficiently store 20k strings in an array with variable depths, we can use a multi-dimensional array where each level represents a different depth. This allows us to organize the strings based on their depth without the need for separate arrays. By using nested arrays, we can easily access and manipulate the strings at different depths.

// Initialize an empty multi-dimensional array to store strings with variable depths
$stringsArray = [];

// Example of storing a string at a specific depth
$depth1 = 0;
$depth2 = 1;
$depth3 = 2;
$string = "Example String";

$stringsArray[$depth1][$depth2][$depth3] = $string;

// Example of accessing a string at a specific depth
echo $stringsArray[$depth1][$depth2][$depth3]; // Output: Example String