如何从php中转换为数组的Object中退出值?

Vim*_*deo 3 php arrays

我想检索转换为数组的值,然后检索对象..

$input = (object)(array) 123;
var_dump($input);
Run Code Online (Sandbox Code Playgroud)

这输出:

object(stdClass)#1 (1) {
  [0]=>
  int(123)
}
Run Code Online (Sandbox Code Playgroud)

如何从中检索值123 $input

Dav*_*dom 5

https://bugs.php.net/bug.php?id=45959

不幸的是,这是一个众所周知的问题,你无能为力.

如果您从外部源中遇到此类型的对象,最好的选择是将其强制转换为数组以获取值:

$input = (object)(array) 123;
$array = (array) $input;
echo $array[0];
Run Code Online (Sandbox Code Playgroud)