【问题标题】:Is it possible to put an array into a php string? [duplicate]是否可以将数组放入php字符串中? [复制]
【发布时间】:2018-05-02 08:00:32
【问题描述】:

是否可以将数组中的结果放入字符串中?

     <? foreach($get->artist->tags->tag as $tags) {
    $tags = (array) $tags;?>

 <? echo $tags['name'];?>

    <?}?>   

是否也可以创建一个用逗号分隔所有 $tagsnames 的字符串?

例如,假设标签是

House Electronic Pop R&B

是否可以创建这样的字符串

$mystring = House,Electronic,Pop,R&B

谢谢

更新:

$laststation = implode(',', array_column($get->artist->tags->tag, 'name'));
$laststation = addslashes($laststation);
$laststation_array = explode(',', $laststation);
$laststation_search = implode("%' OR `tags` LIKE '%", $laststation_array);

$query5 = mysql_query ( "SELECT * FROM `Stations` WHERE `tags` LIKE '%".$laststation_search."%' AND `status` = 'Online'  ORDER BY RAND() LIMIT 8" );

我已尝试使用上述内爆,但似乎没有返回任何结果。

【问题讨论】:

  • implode(',', array_column($get-&gt;artist-&gt;tags-&gt;tag, 'name'));
  • 一个简单的网络搜索会为您自己回答这个问题。在询问之前需要进行基础研究
  • 试过这个,但似乎没有任何结果:/
  • @splash58 - 我已经更新了上面的代码,任何帮助将不胜感激

标签: php


【解决方案1】:

您可以使用以下方法增加数字:

$var++;

$var += 1;

你也可以在字符串中添加东西:

$string = '披萨';

$string .= ", 汉堡包";

或者你也可以使用implode()

【讨论】:

    【解决方案2】:

    我想你想要 implode 命令。它接受一个数组并将其粘合成一个字符串。

    http://php.net/manual/en/function.implode.php

    【讨论】:

      猜你喜欢
      • 2018-08-31
      • 1970-01-01
      • 1970-01-01
      • 2013-08-03
      • 1970-01-01
      • 1970-01-01
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多