【问题标题】:Can you please help how to understand assign values to PHP array?您能否帮助理解如何为 PHP 数组赋值?
【发布时间】:2021-11-23 14:43:18
【问题描述】:

大家好)希望这个 10 月的星期六你一切都好......

现在在 php 上学习自定义 CMS 的路线主题。
并得到下一个代码,不明白..
所以我们有函数 Routes(),它返回控制器的方法,如果它是发送的话。

下一行让我感到困惑( 我们称之为“$this->routes”,但紧随其后,我们输入括号“[strtoupper(method)][pattern]”
伙计们,这是什么意思?

此外,在之前的视频中,我们还有数组属性 $routes。
他正在以这种方式添加路线

当作者写 $this->routes[strtoupper(method)][pattern] 我们正在使用时,你能帮忙吗 这里路由为数组?
如果它的数组那么你怎么能在这里分配2个值?我的意思是[方法]和[模式]?

【问题讨论】:

标签: php function routes


【解决方案1】:

它是一个多维数组。下面的例子:

$name = 'john doe';

$array = [
   'firstLevel' => [
      'secondLevel' => [
          'thirdLevel' => $name
       ]
    ]
];

如果我得到价值 'john doe' 写

$array['firstLevel']['secondLevel']['thirdLevel'].

【讨论】:

  • 非常感谢!我现在会读到它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-17
  • 1970-01-01
  • 1970-01-01
  • 2018-12-22
相关资源
最近更新 更多