to start i am terrible with loops and arrays.
I have a txt file that i can turn into an array using file() but i need to pull the data from the text file into my code to create the code for making an array, not put the data into an actual array.
i need to turn:
cat
dog
mouse
into the following code dynamically (i do not need to make an actual outputted array, i need to create the code dynamically somehow).:
Array('cat'=>'cat','dog'=>'dog','mouse'=>'mouse')
My problem is that i need to do the following:
txt file input:
Crafts & Sewing\Sale\Sale\Sale on Crafts & Sewing
Crafts & Sewing\Sale\Sale\Crafts & Sewing Sale
Each item is on a seperate line of the txt file (over 10k lines)
Output (not browser output, still in code):
$somevariable = Array('line1' => 'line1', 'line2' => 'line2')
But everything i try gives me the actual array.
I need to create the actual CODE for an array by taking each line of the text file and pulling it into my code and adding in the commas, and quotes, and => without actually going through and manually adding that all to 10k lines of code.
basically i have a HUGE list in a text file and instead of going through and manually adding and editing over 10k lines of the text file to be in that format and then cluttering up my code with that, i want to put it all into the correct format programatically and then just use that variable in my code rather than 10k lines of code. This also allows me to edit the text file with new content whenever it changes without needing to edit the code.
I am using it to create a dropdown in a site that take the format as follows:
array(
'id' => 'quality',
'type' => 'select',
'label' => __('Quality', 'esc_vff'),
'options' => array(
'New' => 'New',
'Used' => 'Used',
'Refurbished' => 'Refurbished'
),
'description' => __('Overstock data for "Quality" column.', 'esc_vff'),
'desc_tip' => true,
)
in the end i would like to be able to do something like change:
'options' => array(
'New' => 'New',
'Used' => 'Used',
'Refurbished' => 'Refurbished'
),
to:
'options' => $myarrayfromtextfile,
where $myarrayfromtextfile is a variable or something that gives me the code that should be put there, but isnt 10k lines of code.
maybe to better clarify: an array printed out has the brackets... i need to find a way to print out the code structure of the array (i dunno if thats the best way to word this) because i am taking a bunch of lines of text and trying to format it to look like i went through and wrote the comma seperated code version of the array
array('foo' => 'foo' , 'bar' => 'bar' )
so i need a variable that when dropped into another array gets compiled/converted to the physical code structure, not the final browser rendered array with length counts and brackets...
Or ill take any other ideas on how to make 10k lines of text end up looking like
array('foo' => 'foo' , 'bar' => 'bar' )
without going line by line adding in commas and => and ''