如何获取PHP函数值?

发布于 2025-01-01 06:04:09 字数 396 浏览 1 评论 0原文

例如,当使用函数“get_photo_id”时,我在里面使用数字 6。

示例:

<?php get_photo_id("6"); ?>

我希望函数 get_photo_id 获取内部的值(在本例中为 6)。能够找到里面的数字并为其分配一个变量。

像这样的事情:

function get_photo_id() {

<!--something to find the value used and assign it as $valueused -->

get_cat_id('$valueused')
echo 'cat_id'
}

我希望你明白我的意思...我是 php 的新手!

When using a funciton for example, "get_photo_id" and I use the number 6 inside.

EXAMPLE:

<?php get_photo_id("6"); ?>

i want the function get_photo_id to get the value inside (which is 6 in this case). To be able to find the number inside and assign a variable to it.

Something like this:

function get_photo_id() {

<!--something to find the value used and assign it as $valueused -->

get_cat_id('$valueused')
echo 'cat_id'
}

I hope you get what i mean... im kind of new in php!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

春夜浅 2025-01-08 06:04:09

函数参数按如下方式传递:

function foo($argument1, $arg2)
{
    var_dump($argument1, $arg2, func_get_args());
}

foo("test", 12);

结果为

string(4) "test"
int(12)
array(2) { [0]=> string(4) "test" [1]=> int(12) }

Function arguments are passed as follows:

function foo($argument1, $arg2)
{
    var_dump($argument1, $arg2, func_get_args());
}

foo("test", 12);

results in

string(4) "test"
int(12)
array(2) { [0]=> string(4) "test" [1]=> int(12) }
雪若未夕 2025-01-08 06:04:09

你指的是函数参数吗?

function foo($arg)
{
    echo $arg;
}

当您调用 foo("6") 时,它将回显 6。但是,如果您想使用数字,最好使用数字调用 foo(6),而不是包含数字的字符串。

Do you mean function parameters?

function foo($arg)
{
    echo $arg;
}

When you call foo("6") it will echo 6. However, if you want to work with numbers, its better to call foo(6) with a number, instead of a string containing a number.

装纯掩盖桑 2025-01-08 06:04:09

我不清楚你的问题,但这可能是我理解的答案

function get_photo_id($value) {

    <!--something to find the value used and assign it as $valueused -->

    get_cat_id($value);
    echo 'cat_id'
}

I am not clear about your question, but this might be the answer from what i understand

function get_photo_id($value) {

    <!--something to find the value used and assign it as $valueused -->

    get_cat_id($value);
    echo 'cat_id'
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文