将数组与非数组值进行比较

时间:2017-03-02 02:13:27

标签: php arrays

我试图将值与数组中的另一个值进行比较。但是,即使我有两个不同的值(一个是10,数组中的其他值是4和6),该消息也只显示$scope.showDialog(`<div class="md-dialog-container" id="functionality"> <md-dialog aria-label="Dialog"> <md-input-container> <label>Who do you want to assign to build functionality?</label> <md-select ng-model="startAppController.fluff"> <md-optgroup label="Select an Employee"> <md-option ng-value={{employee.name}} ng-repeat="employee in staff" ng-selected="true">{{employee.name}}</md-option> </md-optgroup> </md-select> </md-input-container> <div> <md-input-container flex-gt-xs> <md-button type="submit" class="md-raised md-primary" ng-click="startAppController.assign()">Assign Work!</md-button> </md-input-container> </div> </md-dialog> </div>`);

exits in array 2

给出值

if (in_array($post,$orderP)==0){
    echo ' exists in array2';
}else{
    echo 'does not exists in array2';
}

echo $post; //gives a value of 10
echo var_dump ($orderP); 

2 个答案:

答案 0 :(得分:2)

你有多维数组,所以试试这样的

$ids = array_column($orderP, 'post_ID');

if (in_array($post,$ids)){
            echo ' exists in array2';
            }
else{
            echo 'does not exists in array2';
            }

答案 1 :(得分:0)

我不认为in_array会递归检查,,,可能有更好的代码..但我的解决方案是......

$bool = false;
foreach($orderP as $order){

  if (in_array($post,$order)){
     echo ' exists in array2';
     $bool=true;
     return;
  }
}

if(!$bool){

    echo 'does not exists in array2';

}