dsizmmwnm56437180 2014-10-15 20:56
浏览 48

为什么array_push()不将pdo查询对象作为参数

Just curious. When pushing an array on another:

array_push($array_1, $array_2);

I get the usual behavior, but when I push a pdo query->fetchAll which contains and returns an array, nothing happens.

array_push($array_1, $query->fetchAll());

What is interesting to me is, if I assign the query object to a variable:

$array_fetchAll = $query->fetchAll();
array_push($array_1, $array_fetchAll);

It works like expected.

  • 写回答

1条回答 默认 最新

  • doushenyu8228 2014-10-16 00:40
    关注

    The only way this would work is using PHP version 5.5.X or above where a new feature allow functions to be dereferenced directly to access individual elements.

    For example echo $stmt->fetchAll()[0]; would not work if you running PHP older than 5.5.x

    array_push requires an array as parameter, if you are using older PHP you must store $query->fetchAll() into a variable.

    评论

报告相同问题?

悬赏问题

  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置