使用时,内爆数组字符串的转换通知 [英] Array to string conversion notice when using implode

查看:135
本文介绍了使用时,内爆数组字符串的转换通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个字符串我从一个JSON数组了,我投入像这样另一个数组:

I have multiple strings I got from a json array which I put into another array like so:

$myArray = $anotherArray = new array();

if($stringA != ""){
     $myArray[] = $stringA;
}elseif($stringB != ""){
     $myArray[] = $stringB;
} //so on...

我想把这一切在数据库中的一列,所以我推到字符串数组1。然后,我转换使用破灭数组:

I want to put all of this in the database in a single column so I push the strings into 1 array. Then, I convert the array using implode:

if(is_array($myArray)){
    $newString = implode(" ", $myArray);
}

本精美曾在我的本地主机,但是当我们移动的文件到服务器并通过cron运行它,我接到通知阵列字符串转换。

This worked fine in my localhost but when we moved the file to a server and run it via cron, I received the notice Array to string conversion.

我用对不同组串相同的文件类似code,但所以我不知道是怎么回事,一个没有得到一个错误。

I've used similar code on the same file for different sets of strings but that one did not get an error so I'm not sure what's going on here.

我在像这样的破灭功能使用array_values​​也尝试:

I've also tried using array_values in the implode function like so:

$newString = implode(" ", array_values($myArray));

但是,这也不能工作。我不知道,如果这不是意味着什么,但也有一些情况,其中除了常规文本中,我得到的印刷以及字阵。所以我的问题是,什么是这个错误的可能原因以及如何解决这个问题?

But that didn't work either. I'm not sure if this means anything either but there are some instances wherein aside from the regular text, I get the word Array printed as well. So my question is, what's the possible cause of this error and how can I address it?

推荐答案

您可以只json_en code阵列?

You can just json_encode your array?

$newString  = json_encode($myArray);

和还通知可能是因为你的字符串中的一个可能是一个数组,你可能没有看到这对本地主机,因为你不能有错误报告在PHP开启。

And also the notice is probably because one of your strings are probably an array and you probably do not see this on your localhost because you must not have error reporting turned on in your php.

尝试添加这对您的cron作业的脚本。

Try adding this to your cron job script.

ini_set('display_errors','On');
error_reporting(E_ALL);

这篇关于使用时,内爆数组字符串的转换通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆