如何从PHP的COM对象返回的多维变量数组中读取数据? [英] How do you read from a multidimensional variant array returned from a COM object in PHP?

查看:118
本文介绍了如何从PHP的COM对象返回的多维变量数组中读取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个COM对象,该对象返回多维VARIANT数组(vt_array),并且正在尝试从该数组中读取值.

I'm working with a COM object that returns a multidimensional VARIANT array (vt_array), and I'm trying to read values from the array.

当我使用print_r($mdArray)时,它会显示variant Object. (variant_get_type($mdArray)返回8204.)

When I use print_r($mdArray) it displays variant Object. (variant_get_type($mdArray) returns 8204.)

我尝试使用foreach ($mdArray as $oneArray),但收到消息:

I tried using foreach ($mdArray as $oneArray) but I get the message:

警告:Loader :: getfields()[loader.getfields]:只能处理 一维变体数组(此 数组中有2)个 C:\ Inetpub \ wwwroot \ root \ script \ fileloader.php 在第135行致命错误:未捕获 带有消息的异常异常" '类型变体的对象未创建 一个迭代器 C:\ Inetpub \ wwwroot \ root \ script \ fileloader.php:135 堆栈跟踪:#0 C:\ Inetpub \ wwwroot \ root \ script \ fileloader.php(135): 加载器:: getfields()#1 C:\ Inetpub \ wwwroot \ root \ testloader.php(21): 加载程序-> getfields()#2 {main}抛出 在 C:\ Inetpub \ wwwroot \ root \ script \ fileloader.php 在第135行

Warning: Loader::getfields() [loader.getfields]: Can only handle single dimension variant arrays (this array has 2) in C:\Inetpub\wwwroot\root\script\fileloader.php on line 135 Fatal error: Uncaught exception 'Exception' with message 'Object of type variant did not create an Iterator' in C:\Inetpub\wwwroot\root\script\fileloader.php:135 Stack trace: #0 C:\Inetpub\wwwroot\root\script\fileloader.php(135): Loader::getfields() #1 C:\Inetpub\wwwroot\root\testloader.php(21): Loader->getfields() #2 {main} thrown in C:\Inetpub\wwwroot\root\script\fileloader.php on line 135

(foreach循环位于第135行)

(The foreach loop is on line 135)

我只能获得关于数组的唯一信息,方法是使用count($mdArray)并返回8.

The only information I can get about the array is by using count($mdArray) which returns 8.

如果这里的任何人有阅读多维VARIANT数组的经验,请告诉我该怎么做.

If anyone here has any experience reading from multidimensional VARIANT arrays please tell me how this can be done.

推荐答案

尝试通过"VBScript"提取数组值.是的,您没看错...

Try this to extract array values through "VBScript". Yes, you read that right...

<?php

$com = new COM("MSScriptControl.ScriptControl");
$com->Language = 'VBScript';
$com->AllowUI = false;
$com->AddCode('
    Function getArrayVal(arr, indexX, indexY)
        getArrayVal = arr(indexX, indexY)
    End Function
');

$y1 = 0;
$y2 = 1;
for ($x=0; $x < count($mdArray); $x++) {
    echo $com->Run('getArrayVal', $mdArray, $x, $y1) . ": ";
    echo $com->Run('getArrayVal', $mdArray, $x, $y2) . "\n";
    }

?>

在VBScript创建的数组上进行了良好的测试,否则,当试图强制它像PHP数组一样工作时,它给了我与您完全相同的问题和错误.由PHP和VBscript的邪恶结合所产生的上述方法应该可以逐个提取值.

Tested good on a VBScript-created array, which otherwise gave me the exact same issues and errors as you when trying to coerce it to behave like a PHP array. The above method spawned by the unholy union of PHP and VBscript should extract values piece by piece just fine.

要解释$y1 = 0; $y2 = 1;,请记住VBScript函数的参数是byref,因此除了变量外,您什么都不能传入.

To explain $y1 = 0; $y2 = 1;, keep in mind the parameters of the VBScript function are byref, so you can't pass anything in except a variable.

添加了$com->AllowUI = false以关闭所有屏幕弹出窗口.否则,如果通过某种方式从VBScript调用了MsgBox()并且没有人在服务器终端上单击确定",它将冻结该请求.

Added $com->AllowUI = false to shut off any on-screen popups. Otherwise it would freeze the request if a MsgBox() somehow got called from VBScript and no one was at the server terminal to click 'ok'.

这篇关于如何从PHP的COM对象返回的多维变量数组中读取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆