문제

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