我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

PHP,变量和函数在单独的文件中[重复]

This question already has an answer here:

  • Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors? 3 answers

I have 2 files:

file1 - variables.php

$variable = something;

and file2 - functions.php

function somefunction() {    
    do_something_with $variable;
}

How can I use variable, defined in one file, in function defined in second file?

</div>

use include_once / require_once "file2" inside file1 and call the "somefunction" with $variable as argument.

近期文章

  • 在MySQL中更新排序的最快方法
  • 无法使用INSERT INTO写入数据库
  • 密码字母数字PHP没有使用正则表达式
  • 使用新URL动态生成网页[关闭]
  • 如何使用Rawurldecode()转换为链接? [关闭]
  • 更新php中的单个列1或2 [关闭]
  • 注意:第57行的数组转换为字符串[关闭]
  • 如何制作一个避免注入的SQLite查询?
  • 使用route php page时,默认控制器无法正常工作
  • 将if / else嵌套在另一个if / else中
  • PHP:插入数据时自动创建唯一ID [关闭]
  • PHP函数作用域调用函数内的函数[关闭]
  • 如何在PHP中获取上传图像的宽度和高度[重复]
  • 如何在codeigniter中更改密码并使用jquery验证字段
  • PHP上传后图像变得怪异(失去所有质量)
  • PHP数组值
  • 平方和与立方 和
  • 各位大佬,这个问题选啥呀?
  • 各位大佬,这个问题选啥呀?
  • 程序改错,按要求输出结果,求解。

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华