PHP 内爆功能不起作用

发布于 2024-12-14 12:49:39 字数 284 浏览 0 评论 0原文

我有一个数组,我想通过 implode 函数将该数组转换为逗号分隔的字符串,但这不起作用。我的代码如下。

 <?php 
$relatedSlides = $result['RelatedSlideshows'];
  $relatedSlides = implode(",",$relatedSlides);
   echo $relatedSlides;
  ?>

$结果['相关幻灯片'];是一个数组,并且打印完美。这不是多维数组。这是简单的数组。我怎么做这个???

i have an array and i want to convert this array in comma seprated string by implode function but this is not working. my code is below.

 <?php 
$relatedSlides = $result['RelatedSlideshows'];
  $relatedSlides = implode(",",$relatedSlides);
   echo $relatedSlides;
  ?>

$result['RelatedSlideshows']; is an array and it is printing perfectly. this is not an multidimensional array. this is simple array. how i do this???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

Bonjour°[大白 2024-12-21 12:49:41

我猜这是 mysql_fetch_array() 或 mysql_fetch_assoc() 的结果。
如果您想从结果中内爆数组关联数组,请尝试 implode(",",$result);

但一定要使用 mysql_fetch_assoc(),因为 mysql_fetch_array() 返回 2 个合并数组,1 个关联数组和 1 个数字数组。

I guess that's a result from a mysql_fetch_array() or mysql_fetch_assoc().
If you want to implode the array associative array from the result, try implode(",",$result);

But be sure to use mysql_fetch_assoc(), because mysql_fetch_array() returns 2 merged arrays, 1 associative and 1 numeric.

耳钉梦 2024-12-21 12:49:40

simpleXML 对象不是数组。它是一个在某些情况下可以像数组一样对待的对象。 手册参考

SimpleXML 扩展提供了一个非常简单且易于使用的用于将 XML 转换为可以使用普通属性选择器和数组迭代器处理的对象的工具集。

尝试:

$relatedSlides = array();
$it = $result->RelatedSlideshows->getIterator();
// Iterate over the values in the ArrayObject:
foreach ($it as $key=>$val)
{
    $relatedSlides[] = $val;
}
 $relatedSlides = implode(",",$relatedSlides);

A simpleXML object is not an Array. It is an object that under some circumstances can be treated like an array. Manual Reference

The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators.

Try:

$relatedSlides = array();
$it = $result->RelatedSlideshows->getIterator();
// Iterate over the values in the ArrayObject:
foreach ($it as $key=>$val)
{
    $relatedSlides[] = $val;
}
 $relatedSlides = implode(",",$relatedSlides);
独闯女儿国 2024-12-21 12:49:40
<?php
ini_set('display_errors',1);  error_reporting(E_ALL);
$relatedSlides = $result['RelatedSlideshows'];
  $relatedSlides = implode(",",$relatedSlides);
   echo $relatedSlides;
?>

给我:

Notice:  Undefined variable: result in ******.php on line 4

Warning:  implode() [function.implode]: Invalid arguments passed in ******.php on line 5

希望里面有足够的隐含提示。

编辑:

尝试:

   $relatedSlides = $result['RelatedSlideshows'] -> RelatedSlideshowID;
<?php
ini_set('display_errors',1);  error_reporting(E_ALL);
$relatedSlides = $result['RelatedSlideshows'];
  $relatedSlides = implode(",",$relatedSlides);
   echo $relatedSlides;
?>

Gives me:

Notice:  Undefined variable: result in ******.php on line 4

Warning:  implode() [function.implode]: Invalid arguments passed in ******.php on line 5

Hopefully there is enough implicit tips in there.

Edit:

try:

   $relatedSlides = $result['RelatedSlideshows'] -> RelatedSlideshowID;
赠我空喜 2024-12-21 12:49:40

那么您的原始数组有问题,请检查

对 $result['RelatedSlideshows'] 进行 var 转储。

Something's wrong with your original array then, check this out.

Do a var dump of $result['RelatedSlideshows'].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文