I have a basic survey builder and if the user specifies that the question requires one answer from a list (dropdown) then each possible answer needs to be saved in database.

Therefore my view has has a textarea were the admin can input the available answers and separates them with line breaks. I need to pull that text (line by line) and save in array so that my model can create a row per item.

My only issue is how to separate each line and save as array. The view is actually a popup and the data is sent using Ajax therefore the easiest way is to send the entire value as one input to the controller and then separate it in PHP. I was wondering if Laravel has a function ready for this or if I should use standard PHP such as str_replace etc...

有帮助吗?

解决方案

as simple as this:

$lines = explode(PHP_EOL, $string);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top