I have a text file that contains a list of arrays:
'1920s' => array('20s','twenties')
'1930s' => array('30s','thirties')
'1940s' => array('40s','forties')
'1950s' => array('50s','fifties')
I want to import it as an array of arrays, like this:
Array
(
[1920s] => Array
(
[0] => 20s
[1] => twenties
)
[1930s] => Array
(
[0] => 30s
[1] => thirties
)
[1940s] => Array
(
[0] => 40s
[1] => forties
)
[1950s] => Array
(
[0] => 50s
[1] => fifties
)
)
I import the file:
$decadesFile = file_get_contents('/Users/derwood/capsule/decades.txt');
$decades = explode("\r",$decadesFile);
But I get an array of lines of text:
Array
(
[0] => '1920s' => array('20s','twenties')
[1] => '1920s' => array('20s','twenties')
[2] => '1940s' => array('40s','forties')
[3] => '1950s' => array('50s','fifties')
Is there another combination besides "file_get_contents" and "explode" I should be using?
Edit: I indeed read the answer listed, but the text file is being generated by a FMP database, not print_r output, so with my limited experience I didn't think the question was a duplicate. However, the linked question and the answers here are all very helpful in illustrating how they are related. Thank you.