将字符串插入数组时出现问题
我试图将一个内爆生成的字符串插入到一个数组中,然后用于 json 实现
内爆生成的字符串看起来像这样
'id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]
我想在这段代码中使用它
$this->_JsonArr[]=array($Generated string);
来实现类似的东西,
$this->_JsonArr[]=array('id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]);
而不是我得到类似的
$this->_JsonArr[]=array(" 'id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]");
东西就像生成的字符串被视为一个元素作为键和值对。 显然我可以因此从 mysql 获得预期的输出,任何人都可以帮助我解决这个问题
i'm trying to insert an implode generated string to an array that then later be used for json implementation
the implode generated string is look like this
'id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]
i would like to used it in this code
$this->_JsonArr[]=array($Generated string);
to achieve something like this
$this->_JsonArr[]=array('id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]);
instead i got something like this
$this->_JsonArr[]=array(" 'id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]");
seem like generated string is treated as one element as key and value pair.
obviously i can get expected output from mysql because of this, can anybody help me with this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么你需要内爆任何东西?只需传递数组:
我认为您想要做的完整解决方案是这样的(即您问题中的第三个代码框):
Why do you need to implode anything? Just pass the array:
I think a full solution to what you want to do is something like this (i.e., the third code box in your question):
看起来您想要使用数组键和值,但正如我看到您放入数组纯字符串中,期望数组以以下格式解析您的纯字符串:keys =>价值观。
您可以尝试像下面这样创建数组:
(如果我错误理解你的问题,请纠正我)。
Looks like you want use arrays keys and values, but as I see you put into array plain string with expectation that array parse your plain string in format: keys => values.
You can try create array like below:
(Please correct me if I wrong understand your question).