php dirtoarray,PHP Ds\Stack toArray()用法及代码示例
PHP的Ds \ Stack::toArray()函數用于將堆棧轉換為數組并返回轉換后的數組。此功能不會修改實際的堆棧。
用法:
void public Ds\Stack::toArray ()
參數:該函數不接受任何參數。
返回值:此函數返回從堆棧生成的數組。
以下示例程序旨在說明Ds \ Stack::toArray()函數:
程序1:
// PHP program to illustarte the
// toArray() function
// Create a Stack instance
$stack = new \Ds\Stack();
// Pushing elements to Stack
$stack->push("Welcome");
$stack->push("to");
$stack->push("GfG");
// Print the converted array
print_r($stack->toArray());
// Print the Stack
print_r($stack);
?>
輸出:
Array
(
[0] => GfG
[1] => to
[2] => Welcome
)
Ds\Stack Object
(
[0] => GfG
[1] => to
[2] => Welcome
)
程序2:
// PHP program to illustarte the
// toArray() 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 converted Array
print_r($stack->toArray());
// Print the Stack
print_r($stack);
?>
輸出:
Array
(
[0] => 5.5
[1] => 10
[2] => GfG
[3] => to
[4] => Welcome
)
Ds\Stack Object
(
[0] => 5.5
[1] => 10
[2] => GfG
[3] => to
[4] => Welcome
)
總結
以上是生活随笔為你收集整理的php dirtoarray,PHP Ds\Stack toArray()用法及代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用户开小号“浇水”套取蚂蚁森林绿色能量被
- 下一篇: SMO算法最通俗易懂的解释(SVM中的S