duanguo7021 2010-08-17 11:01
浏览 37
已采纳

php字符串变量,包含数组函数的输入

Why this does not work?

  $stringhaha ="     1 => General,
      2 => Business,
      3 => Entertainment,
      4 => Health,
      5 => Politics,
      6 => Sci/Tech,
      7 => Sports,
      8 => News";

$all_categories = array($stringhaha);

print_r($all_categories);

(will give an array with 1 item.)

While this works: If I include the variable content like this it will create properly an array with 8 items:

$all_categories = array(1 => General,
      2 => Business,
      3 => Entertainment,
      4 => Health,
      5 => Politics,
      6 => Sci/Tech,
      7 => Sports,
      8 => News);

print_r($all_categories);
  • 写回答

3条回答 默认 最新

  • douxiu6835 2010-08-17 11:06
    关注

    What is happening is exactly what you should expect: you've declared an array that contains one string.

    It doesn't matter that your string looks like an array to us humans, PHP is merely PHP, and can't magically detect that you want it to parse an array from a string.

    giorgio79, meet PHP Docs, your new best friend.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 深度学习残差模块模型
  • ¥20 两个不同Subnet的点对点连接
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)