Php 单个数组中允许使用相同的密钥
我使用了使用php mongodb驱动程序的mongodb数据库。新的mongodb驱动程序遵循一些条件来执行查询。在我的代码中,我需要两个或多个条件。当我创建一个包含两个或多个条件的数组时,此条件数组中包含相同的键附件。实际上,我希望数组中有相同的键 下面是我创建的数组结构:-Php 单个数组中允许使用相同的密钥,php,mysql,mongodb,Php,Mysql,Mongodb,我使用了使用php mongodb驱动程序的mongodb数据库。新的mongodb驱动程序遵循一些条件来执行查询。在我的代码中,我需要两个或多个条件。当我创建一个包含两个或多个条件的数组时,此条件数组中包含相同的键附件。实际上,我希望数组中有相同的键 下面是我创建的数组结构:- Array ( [listingStatus] => Active [$or] =>
Array
(
[listingStatus] => Active
[$or] =>
Array
(
[0] => Array
(
[propertyType.propertyType] => MongoDB\BSON\Regex Object
(
[pattern] => ^single family
[flags] => i
)
)
[1] => Array
(
[propertySubType.propertySubType] => MongoDB\BSON\Regex Object
(
[pattern] => ^single family
[flags] => i
)
)
)
[0] => Array
(
[$or] => Array
(
[0] => Array
(
[address.fullStreetAddress] => MongoDB\BSON\Regex Object
(
[pattern] => ^florida
[flags] => i
)
)
[1] => Array
(
[address.postalCode] => MongoDB\BSON\Regex Object
(
[pattern] => ^florida
[flags] => i
)
)
[2] => Array
(
[address.city] => MongoDB\BSON\Regex Object
(
[pattern] => ^florida
[flags] => i
)
)
[3] => Array
(
[mlsNumber] => MongoDB\BSON\Regex Object
(
[pattern] => ^florida
[flags] => i
)
)
)
)
)
上面是我在这个数组中创建的数组,我使用了array_push方法,但mongodb需要第二个或内部数组外部的条件,上面的代码返回我在第二个或条件中创建新数组
以下是我的代码:-
$dataSend = array('listingStatus' => 'Active');
$propCondition[] = array('propertyType.propertyType' => new MongoDB\BSON\Regex("^$text", 'i'));
$propCondition[] = array('propertySubType.propertySubType' => new MongoDB\BSON\Regex("^$text", 'i'));
$dataSend['$or'] = $propCondition;
$nameCondition = [];
$nameCondition[] = array('address.fullStreetAddress' => new MongoDB\BSON\Regex("^$request->list", 'i'));
$nameCondition[] = array('address.postalCode' => new MongoDB\BSON\Regex("^$request->list", 'i'));
$nameCondition[] = array('address.city' => new MongoDB\BSON\Regex("^$request->list", 'i'));
$nameCondition[] = array('mlsNumber' => new MongoDB\BSON\Regex("^$request->list", 'i'));
$dataSend1['$or'] = $nameCondition;
array_push($dataSend, $dataSend1);
print_r($dataSend);
这里我已经在我的第一个数组中创建了数据发送数组,数据发送数组是我的第二个数组,我尝试在第一个数组中推第二个数组
我的预期结果是当数组推送时,第二个数组不创建数组是像对象一样推送的。在我的数组中,第一个键是列表状态,第二个键是$or,最后一个键$or进入数组,实际上它显示在数组外部