如何获得多维数组搜索

时间:2018-06-11 06:07:19

标签: php

我的阵列是: 我如何按'airlinesName'过滤

import { Component, OnInit, OnDestroy } from '@angular/core';

declare var $: any;

    @Component({
      selector: 'app-order',
      templateUrl: './order.component.html',
      styleUrls: ['./order.component.css']
    })
    export class OrderComponent implements OnInit, OnDestroy {

    datatableOptions:{
    ...
    }

    constructor(){
    ...
    }

    ngOnInit(){
    ...
    }

    onRefresh(){
    if ($.fn.DataTable.isDataTable(id)) {
          const table = $(id).DataTable();
          table.ajax.reload();
        }
    }

}

1 个答案:

答案 0 :(得分:2)

你可以试试这个,。,

 $a = [
         [
            'arrival' => [
                'airlinesName' => 'tes1',
                'departureCity' => 'ads'
            ],
             'return' => [
                'airlinesName' => 'tes1',
                'departureCity' => 'ads'
            ]
         ],
        [
            'arrival' => [
                'airlinesName' => 'tes2',
                'departureCity' => 'ads'
            ],
             'return' => [
                'airlinesName' => 'tes2',
                'departureCity' => 'ads'
            ]
         ]
     ];

    $airlinesName = 'tes1';

    $a = array_filter($a, function($x) use ($airlinesName){ return $x['arrival']['airlinesName'] == $airlinesName;});
    print_r($a);