PHP If开关,用于具有未知
只是好奇在PHP If开关,用于具有未知,php,multidimensional-array,arrayiterator,Php,Multidimensional Array,Arrayiterator,只是好奇在if开关中是否有这样做的方法 $account = array ( '{unkown value}' => array ( 'accountID' => '4430290', 'accountStatus' => '1', 'parentAccountID' => '', 'offerID' => '746', 'billingModel' => '2.0', ), );
if
开关中是否有这样做的方法
$account = array (
'{unkown value}' =>
array (
'accountID' => '4430290',
'accountStatus' => '1',
'parentAccountID' => '',
'offerID' => '746',
'billingModel' => '2.0',
),
);
if(array_pop($account)['billingModel'] == 'SomeValue') {
// do stuff
}
我目前正在做这件事,但我认为可能有更好的方法
$model = array_pop($accountInfo);
if ($model['billingModel'] == 'someValue') return false;
若您只想在子数组元素具有某个值时执行某些操作,那个么您必须实际查看数组_search()
较新版本的php允许您像这样链接表达式。示例: php 5.3: php 5.4: 两者使用相同的代码:
<?php
$array = array(range(1,5), range(6,10), range(11, 15));
if(array_shift($array)[0] == 1){
echo "hello";
}
新版本的php允许您链接这样的表达式。我相信它是在5.4中引入的。不幸的是,这需要与5.3兼容,+1才能实现整洁的5.4技巧。@ehime这是我的观点,它不能按照您的要求在5.3中工作。仅在>=5.4中。在5.3中,您必须按照您的建议进行操作,两行或一个循环。foreach或while可以很好地处理未知密钥。