我有一个我正在努力的多维数组。数组就是这样:
$array => Array (1)
(
| ['WHMCSAPI'] => Array (6)
| (
| | ['ACTION'] = String(9) "getorders"
| | ['RESULT'] = String(7) "success"
| | ['TOTALRESULTS'] = String(1) "4"
| | ['STARTNUMBER'] = String(1) "0"
| | ['NUMRETURNED'] = String(1) "4"
| | ['ORDERS'] => Array (4)
| | (
| | | ['ORDER'] => Array (27)
| | | (
| | | | ['ID'] = String(3) "190"
| | | | ['ORDERNUM'] = String(10) "8782265746"
| | | | ['USERID'] = String(2) "66"
| | | | ['CONTACTID'] = String(1) "0"
| | | | ['DATE'] = String(19) "2013-12-31 16:00:42"
| | | | ['NAMESERVERS'] = NULL(0) NULL
| | | | ['TRANSFERSECRET'] = NULL(0) NULL
| | | | ['RENEWALS'] = NULL(0) NULL
| | | | ['PROMOCODE'] = NULL(0) NULL
| | | | ['PROMOTYPE'] = NULL(0) NULL
| | | | ['PROMOVALUE'] = NULL(0) NULL
| | | | ['ORDERDATA'] = String(6) "a:0:{}"
| | | | ['AMOUNT'] = String(4) "4.00"
| | | | ['PAYMENTMETHOD'] = String(9) "authorize"
| | | | ['INVOICEID'] = String(1) "0"
| | | | ['STATUS'] = String(6) "Active"
| | | | ['IPADDRESS'] = String(12) "64.50.180.53"
| | | | ['FRAUDMODULE'] = NULL(0) NULL
| | | | ['FRAUDOUTPUT'] = NULL(0) NULL
| | | | ['NOTES'] = NULL(0) NULL
| | | | ['PAYMENTMETHODNAME'] = String(11) "Credit Card"
| | | | ['PAYMENTSTATUS'] = NULL(0) NULL
| | | | ['NAME'] = String(11) "Chad Riddle"
| | | | ['CURRENCYPREFIX'] = String(1) "$"
| | | | ['CURRENCYSUFFIX'] = String(4) " USD"
| | | | ['FRAUDDATA'] = NULL(0) NULL
| | | | ['LINEITEMS'] => Array (1)
| | | | (
| | | | | ['LINEITEM'] => Array (8)
| | | | | (
| | | | | | ['TYPE'] = String(7) "product"
| | | | | | ['RELID'] = String(3) "488"
| | | | | | ['PRODUCTTYPE'] = String(21) "Other Product/Service"
| | | | | | ['PRODUCT'] = String(46) "SecureLive Addons - SecureLive Addon Domain 10"
| | | | | | ['DOMAIN'] = String(17) "2kplusgateway.org"
| | | | | | ['BILLINGCYCLE'] = String(7) "Monthly"
| | | | | | ['AMOUNT'] = String(9) "$4.00 USD"
| | | | | | ['STATUS'] = String(6) "Active"
| | | | | )
| | | | )
| | | )
| | | ['ORDER1'] => Array (27)
| | | (
| | | | ['ID'] = String(3) "189"
| | | | ['ORDERNUM'] = String(10) "6062113947"
| | | | ['USERID'] = String(2) "66"
| | | | ['CONTACTID'] = String(1) "0"
| | | | ['DATE'] = String(19) "2013-12-31 16:00:38"
| | | | ['NAMESERVERS'] = NULL(0) NULL
| | | | ['TRANSFERSECRET'] = NULL(0) NULL
| | | | ['RENEWALS'] = NULL(0) NULL
| | | | ['PROMOCODE'] = NULL(0) NULL
| | | | ['PROMOTYPE'] = NULL(0) NULL
| | | | ['PROMOVALUE'] = NULL(0) NULL
| | | | ['ORDERDATA'] = String(6) "a:0:{}"
| | | | ['AMOUNT'] = String(4) "4.00"
| | | | ['PAYMENTMETHOD'] = String(9) "authorize"
| | | | ['INVOICEID'] = String(1) "0"
| | | | ['STATUS'] = String(6) "Active"
| | | | ['IPADDRESS'] = String(12) "64.50.180.53"
| | | | ['FRAUDMODULE'] = NULL(0) NULL
| | | | ['FRAUDOUTPUT'] = NULL(0) NULL
| | | | ['NOTES'] = NULL(0) NULL
| | | | ['PAYMENTMETHODNAME'] = String(11) "Credit Card"
| | | | ['PAYMENTSTATUS'] = NULL(0) NULL
| | | | ['NAME'] = String(11) "Chad Riddle"
| | | | ['CURRENCYPREFIX'] = String(1) "$"
| | | | ['CURRENCYSUFFIX'] = String(4) " USD"
| | | | ['FRAUDDATA'] = NULL(0) NULL
| | | | ['LINEITEMS2'] => Array (1)
| | | | (
| | | | | ['LINEITEM3'] => Array (8)
| | | | | (
| | | | | | ['TYPE'] = String(7) "product"
| | | | | | ['RELID'] = String(3) "487"
| | | | | | ['PRODUCTTYPE'] = String(21) "Other Product/Service"
| | | | | | ['PRODUCT'] = String(46) "SecureLive Addons - SecureLive Addon Domain 10"
| | | | | | ['DOMAIN'] = String(11) "jbrowns.com"
| | | | | | ['BILLINGCYCLE'] = String(7) "Monthly"
| | | | | | ['AMOUNT'] = String(9) "$4.00 USD"
| | | | | | ['STATUS'] = String(6) "Active"
| | | | | )
| | | | )
| | | )
| | | ['ORDER4'] => Array (27)
| | | (
| | | | ['ID'] = String(3) "188"
| | | | ['ORDERNUM'] = String(10) "2178188116"
| | | | ['USERID'] = String(2) "66"
| | | | ['CONTACTID'] = String(1) "0"
| | | | ['DATE'] = String(19) "2013-12-31 16:00:34"
| | | | ['NAMESERVERS'] = NULL(0) NULL
| | | | ['TRANSFERSECRET'] = NULL(0) NULL
| | | | ['RENEWALS'] = NULL(0) NULL
| | | | ['PROMOCODE'] = NULL(0) NULL
| | | | ['PROMOTYPE'] = NULL(0) NULL
| | | | ['PROMOVALUE'] = NULL(0) NULL
| | | | ['ORDERDATA'] = String(6) "a:0:{}"
| | | | ['AMOUNT'] = String(4) "4.00"
| | | | ['PAYMENTMETHOD'] = String(9) "authorize"
| | | | ['INVOICEID'] = String(1) "0"
| | | | ['STATUS'] = String(6) "Active"
| | | | ['IPADDRESS'] = String(12) "64.50.180.53"
| | | | ['FRAUDMODULE'] = NULL(0) NULL
| | | | ['FRAUDOUTPUT'] = NULL(0) NULL
| | | | ['NOTES'] = NULL(0) NULL
| | | | ['PAYMENTMETHODNAME'] = String(11) "Credit Card"
| | | | ['PAYMENTSTATUS'] = NULL(0) NULL
| | | | ['NAME'] = String(11) "Chad Riddle"
| | | | ['CURRENCYPREFIX'] = String(1) "$"
| | | | ['CURRENCYSUFFIX'] = String(4) " USD"
| | | | ['FRAUDDATA'] = NULL(0) NULL
| | | | ['LINEITEMS5'] => Array (1)
| | | | (
| | | | | ['LINEITEM6'] => Array (8)
| | | | | (
| | | | | | ['TYPE'] = String(7) "product"
| | | | | | ['RELID'] = String(3) "486"
| | | | | | ['PRODUCTTYPE'] = String(21) "Other Product/Service"
| | | | | | ['PRODUCT'] = String(46) "SecureLive Addons - SecureLive Addon Domain 10"
| | | | | | ['DOMAIN'] = String(14) "blestatest.com"
| | | | | | ['BILLINGCYCLE'] = String(7) "Monthly"
| | | | | | ['AMOUNT'] = String(9) "$4.00 USD"
| | | | | | ['STATUS'] = String(6) "Active"
| | | | | )
| | | | )
| | | )
| | | ['ORDER7'] => Array (26)
| | | (
| | | | ['ID'] = String(3) "187"
| | | | ['ORDERNUM'] = String(10) "9493314051"
| | | | ['USERID'] = String(2) "66"
| | | | ['CONTACTID'] = String(1) "0"
| | | | ['DATE'] = String(19) "2013-12-31 15:58:48"
| | | | ['NAMESERVERS'] = NULL(0) NULL
| | | | ['TRANSFERSECRET'] = NULL(0) NULL
| | | | ['RENEWALS'] = NULL(0) NULL
| | | | ['PROMOCODE'] = NULL(0) NULL
| | | | ['PROMOTYPE'] = NULL(0) NULL
| | | | ['PROMOVALUE'] = NULL(0) NULL
| | | | ['ORDERDATA'] = String(6) "a:0:{}"
| | | | ['AMOUNT'] = String(4) "4.00"
| | | | ['PAYMENTMETHOD'] = String(9) "authorize"
| | | | ['INVOICEID'] = String(1) "0"
| | | | ['STATUS'] = String(6) "Active"
| | | | ['IPADDRESS'] = String(12) "64.50.180.53"
| | | | ['FRAUDMODULE'] = NULL(0) NULL
| | | | ['FRAUDOUTPUT'] = NULL(0) NULL
| | | | ['NOTES'] = NULL(0) NULL
| | | | ['PAYMENTMETHODNAME'] = String(11) "Credit Card"
| | | | ['PAYMENTSTATUS'] = NULL(0) NULL
| | | | ['NAME'] = String(11) "Chad Riddle"
| | | | ['CURRENCYPREFIX'] = String(1) "$"
| | | | ['CURRENCYSUFFIX'] = String(4) " USD"
| | | | ['FRAUDDATA'] = NULL(0) NULL
| | | )
| | )
| )
)
基本上我想要获得的是订单ID,它基本上是$ array ['WHMCSAPI'] ['ORDERS'] ['ORDER'] ['ID'],通过搜索域名,即$阵列[ 'WHMCSAPI'] [ '订单'] [ 'ORDER'] [ '了LineItem'] [ 'LINEITEM'] [ 'DOMAIN']
请注意,“ORDER”键会发生变化,“LINEITEMS”和“LINEITEM”也会发生变化。
因此,如果我要搜索jbrowns.com,它会撤回订单编号189,或者如果我正在搜索最新版本,它将会撤回id 188。
我尝试过array_walk,array_search和许多预先构建的函数,这些函数没有提供我需要的信息。有没有人遇到过这种情况。
这基本上适用于WHMCS,这是getorders API函数。如果我的一个客户需要从网站取消他们的服务,API函数'deleteorder'需要orderid,而我获得订单ID的唯一方法是搜索他们想要取消的域名。
任何帮助都会非常有用。
谢谢, 杰夫
答案 0 :(得分:2)
试试这个..
<?php
$domain = "www.your-domain.com";
$order_id = 0;
$found = FALSE;
if (!$found) {
foreach ($array as $arr) {
foreach ($arr['ORDERS'] as $ords) {
foreach($ords['ORDER'] as $ord) {
$order_id = $ord['ID'];
foreach($ord['LINEITEMS'] as $litems) {
foreach($litems['LINEITEM'] as $litem) {
if ($litem['DOMAIN'] == $domain) {
$found = TRUE;
break 5;
}
}
}
}
}
}
}
?>
答案 1 :(得分:1)
这对你有用。只需插入您要查找的阵列和域,并分配给变量。
<?php
function getOrderID($searchfor, $input_array){
foreach($input_array['WHMCSAPI']['ORDERS'] as $orderskey => $ordersvalue){
foreach($ordersvalue as $orderkey => $ordervalue){
if(preg_match("/LINEITEMS[1-9]*/i", $orderkey, $match)){
foreach($ordervalue as $key => $value){
if($value['DOMAIN'] == $searchfor){
$orderid = $input_array['WHMCSAPI']['ORDERS'][$orderskey]['ID']."<br/>";
}
}
}
}
}
if(isset($orderid)){
return $orderid;
}else{
return "Domain not found";
}
}
$id = getOrderID("blestatest.com", $array);
echo $id;
?>