【问题标题】:Array of string php [duplicate]字符串php数组[重复]
【发布时间】:2014-05-11 04:52:16
【问题描述】:

我想创建一个字符串数组,但如果我使用变量,我就不能这样做。

$dir_photo="./Foto_NEW/";
$photo= array($dir_photo+"DSCN2507.JPG",$dir_photo+"IMG_0054.JPG",$dir_photo+"IMG_0058.JPG");

结果是 0 0 0。

【问题讨论】:

  • 连接运算符在 PHP 中是.。不是+
  • @StefanoMaglione:它发生了!每个人都曾经是初学者:)

标签: php arrays string


【解决方案1】:

+ 是 Javascript 中的连接运算符,但在 PHP 中是句点 . 所以你需要的是:

$photo= array($dir_photo."DSCN2507.JPG",$dir_photo."IMG_0054.JPG",$dir_photo."IMG_0058.JPG");

【讨论】:

    【解决方案2】:

    您需要将+ 替换为.

    $dir_photo."DSCN2507.JPG"
    

    +用于javascript,.用于php

    【讨论】:

      【解决方案3】:

      试试这个:

      $dir_photo="./Foto_NEW/";
      $photo= array($dir_photo."DSCN2507.JPG",$dir_photo."IMG_0054.JPG",$dir_photo."IMG_0058.JPG");
      

      您需要使用. 而不是+ 来连接字符串。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-04
        • 2017-06-08
        • 2012-08-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多