功能内的关联数组 [英] Associative array within fuction

查看:132
本文介绍了功能内的关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我真的可以在这里提供一些帮助:)

我想显示数组中的所有结果,而不必手工编写所有内容像这样

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号

解决方案

嗨。


您是否尝试替换底部的echo语句?


那么问题很可能是您在函数内定义数组,然后尝试使用该数组功能之外。


创造的任何东西一个函数只存在于该函数内部,除非它以某种方式存在于其他地方。 (通过return关键字或类似的东西)。


尝试在函数外部创建数组,并在需要时将其导入函数。


抱歉,我在回复时犯了一个错误,不知道如何删除它:)



嗨。


您是否尝试替换底部的echo语句?


那么问题很可能是您在函数内定义了数组,然后尝试在函数外部使用该数组。


函数内部创建的任何内容都只存在于该函数内部,除非它以某种方式存在于其他地方。 (通过return关键字或类似的东西)。


尝试在函数外部创建数组,并在需要时将其导入函数中。



Tyvm :)


我在函数外部删除了数组,然后在函数内部删除了一个全局变量。不确定这是否是最好的操作,但是它可以正常工作。


我的Foreach循环运行良好,但在Foreach循环中调用和执行函数时遇到问题。 />

目标:

循环数组并将函数应用于值,然后输出结果。

展开 | 选择 | Wrap | 行号

Hi
I could really do with some help here :)
I am tring to display all of the results from the array without having to write everything out by hand like this

Expand|Select|Wrap|Line Numbers

解决方案

Hi.

Are you trying to replace the echo statements at the bottom?

Then the problem is most likely that you are defining your array inside a function, and then trying to use that array outside the function.

Anything created inside a function will only exists inside that function, unless it is somehow made to exist elsewhere. (via the return keyword or something like that).

Try creating your array outside the function, and import it into the function if you need it.


Sorry I made a mistake with this reply and don''t know how to delete it :)


Hi.

Are you trying to replace the echo statements at the bottom?

Then the problem is most likely that you are defining your array inside a function, and then trying to use that array outside the function.

Anything created inside a function will only exists inside that function, unless it is somehow made to exist elsewhere. (via the return keyword or something like that).

Try creating your array outside the function, and import it into the function if you need it.

Tyvm :)

I decleared the array outside of the function and then decleared a global var inside the function. Not sure if this is the best wat to do it but it works.

I have the Foreach loop working well but am having trouble calling and executing the function in the Foreach loop.

Goal:
Loop through array and apply function to the values and then output the result.

Expand|Select|Wrap|Line Numbers


这篇关于功能内的关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆