php (push) 例子 php,PHP Ds\Stack push()用法及代码示例

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 15:49   3966   0

PHP的Ds \ Stack::push()函数用于在堆栈末尾添加元素。也就是说,它用于将元素压入堆栈。被推送的元素可以是混合数据类型。

用法:

void public Ds\Stack::push ($values)

参数:此函数接受单个参数$values,该参数用于压入堆栈。

返回值:此函数不返回任何值。

以下示例程序旨在说明Ds \ Stack::push()函数:

程序1::

// PHP program to illustarte the

// push() function

// Create a Stack instance

$stack = new \Ds\Stack();

// Pushing elements to Stack

$stack->push("Welcome");

$stack->push("to");

$stack->push("GfG");

// Print the stack

print_r($stack);

?>

输出:

Ds\Stack Object

(

[0] => GfG

[1] => to

[2] => Welcome

)

程序2::

// PHP program to illustarte the

// push() function

// Create a Stack instance

$stack = new \Ds\Stack();

// Pushing Mixed value elements to Stack

$stack->push("Welcome");

$stack->push("to");

$stack->push("GfG");

$stack->push(10);

$stack->push(5.5);

// Print the stack

print_r($stack);

?>

输出:

Ds\Stack Object

(

[0] => 5.5

[1] => 10

[2] => GfG

[3] => to

[4] => Welcome

)

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP