大网数据广告活动
PHP 语言与运行手册

SplFixedArray::setSize · Change the size of an array

· 52CE 我爱测

SplFixedArray::setSize — Change the size of an array

SplFixedArray::setSize

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

SplFixedArray::setSize — Change the size of an array

说明

public function SplFixedArray::setSize(int $size): true

Change the size of an array to the new size of size. If size is less than the current array size, any values after the new size will be discarded. If size is greater than the current array size, the array will be padded with null values.

参数

size

The new array size. This should be a value between 0 and PHP_INT_MAX.

返回值

总是返回 true。

错误/异常

Throws ValueError when size is less than zero.

更新日志

版本 说明
8.4.0 SplFixedArray::setSize() now has a tentative return of true.

示例

示例 #1 SplFixedArray::setSize() example

<?php
   $array = new SplFixedArray(5);
   echo $array->getSize()."\n";
   $array->setSize(10);
   echo $array->getSize()."\n";
?>

以上示例会输出:

5
10

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。