I have a function that takes an entry from a textarea, splits it in to lines and makes an array of the data from each line. However, this is a numerical array, and the data needs to have specific keys associated to it.
Is there a function that can insert these keys in to my desired positions, to avoid manually coding each key?
Here is my code, which produces a 4 element array -
function do_split_invitations(){
/** Split the lines into individual elements in an array */
$lines = explode("\n", $_POST['invitations']);
$invites = array(); // Initiate array to avoid errors
if(!empty($lines)) : foreach($lines as $line) :
$parts = explode(',', $line); // Split in to parts
$parts = array_slice($parts, 0, 4); // Take only the first 4 parts (the rest are not needed
$parts = array_map(array($this, '_clean_callback'), $parts); // Clean the parts
$invites[] = $parts;
endforeach;
endif;
}
Current output (for one line) -
Array
(
[0] => test@adomain.com
[1] => John
[2] => Smith
[3] => Mr Smith
)
Desired output (for one line) -
Array
(
['email'] => test@adomain.com
['first_name'] => John
['surname'] => Smith
['custom'] => Mr Smith
)