PHP 将字符串数组列表转换为数组

标签 php arrays

$str = 'answers[0] = "Love it"; answers[1] = "Hate it."; answers[2] = "Doesnt care"; answers[3] = "Like it";'

如何将其转换为数组?

最佳答案

$str = 'answers[0] = "Love it"; answers[1] = "Hate it."; answers[2] = "Doesnt care"; answers[3] = "Like it";';

preg_match_all('/"(.*)";/U', $str, $matches);
$arr = $matches[1];

var_dump($arr);

关于PHP 将字符串数组列表转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19025404/

相关文章:

php - 将给定时间设置为 00 :00:00 in PHP/MySQL

php - 用于 nodejs 应用程序的 Paypal 快速结帐

php - 尝试通过测验系统获得良好的订单

c - 如何在C中将一个char指针数组复制到另一个

不能在 C 中将 sscanf() 用于字符数组

javascript - 多维数组的 indexOf 语法?

c# - 从c#中的数组中提取半相似项

php - 如何在 IntelliJ 中执行 web 应用程序的 php 脚本?

PHP 关闭 : Can't write files?

c - c中数组初始化的后台发生了什么?