You can create a wrapper function:
function add_to_array($array, $key, $value) { if(array_key_exists($key, $array)) { if(is_array($array[$key])) { $array[$key][] = $value; } else { $array[$key] = array($array[$key], $value); } } else { $array[$key] = array($value); } }
So you just create a two-dimensional array. You can get a โlinked listโ (another array) using regular access to the $array[$key] .
Whether this approach is convenient is up to you.
source share