php - 警告 : array_values() expects parameter 1 to be array

标签 php mysql

我像这样将数据数组插入数据库:

$value['gallery_data'] = array();
$value['gallery_data'] = serialize((array(array_values("name"), array_values("url"), array_values("type")))); // LINE 843

在数据库中:

a:3:{i:0;N;i:1;N;i:2;N;}

我看到了这个错误:

Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\user\modules\editnews.php on line 843

Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\user\modules\editnews.php on line 843

Warning: array_values() expects parameter 1 to be array, string given in C:\xampp\htdocs\user\modules\editnews.php on line 843

编辑:

我需要在数据库中为多个数组插入这种格式:

a:3:{i:0;a:4:{i:0;s:48:"uploads/media/galleries/nature/butterfly_001.jpg";i:1;s:43:"uploads/media/galleries/nature/IMG_4181.jpg";i:2;s:43:"uploads/media/galleries/nature/swan_002.jpg";i:3;s:45:"uploads/media/galleries/nature/zzmed copy.jpg";}i:1;a:4:{i:0;s:19:"test_title";i:1;s:20:"test_title1";i:2;s:25:"test_title2";i:3;s:24:"677777777777777777777777";}i:2;a:4:{i:0;s:19:"test_alt";i:1;s:21:"test_alt1";i:2;s:21:"test_alt2";i:3;s:26:"77888888888888888888888888";}}

我该如何解决这个问题?

最佳答案

我觉得你在数组之前使用了 array_values 所以试试这样的东西

$value['gallery_data'] = serialize(array_values(array("key1" => "name", "key2" => "url", "key3" => "type")));

或者像这样

$value['gallery_data'] = serialize(array("name" , "url", "type")); // LINE 843

关于php - 警告 : array_values() expects parameter 1 to be array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25904665/

相关文章:

PHP 如果日期早于 X 天

python - 如何用不同的Y参数绘制合适的图形?

mysql 子查询错误 [21000][1241] 操作数应包含 1 列

php - MySQL数据库离线调试?

mysql - 将 MySQL 数据库迁移到 SQLite 时出错

javascript - 数据表 : Show action button depending on query

php - 带有下划线的PHP&MYSQL用户名

php - 如何使这个 php 脚本动态化?

php - Ckeditor 并使用 $_POST 插入 Mysql

php - 环境变量如何存储和使用?