-1

I have an array like this

Array
(
    [0] => 
    [
        "18.06.2016",
        "18.06.2016",
        "18.06.2016",
        "Test Test",
        "Test Name",
        "Michael Dean",
        "London",
        "1",
        "980.00",
        "",
        "",
        "875.00",
        "875.00",
        "0",
        "64.81",
        "0",
        "810.19"
    ]
    [1] => 
    [
        "18.06.2016",
        "18.06.2016",
        "18.06.2016",
        "Tray 1",
        "Test Name",
        "Adam Richards",
        "London",
        "1",
        "980.00",
        "",
        "",
        "105.00",
        "105.00",
        "0",
        "7.78",
        "0",
        "97.22"
    ]...

I want to check if the array key value has 1, after London or not?

Like in the first array key, the value goes like this order:

...,"Test Name","Michael Dean","London","1",...

How can I do that?

adams
  • 309
  • 2
  • 17

2 Answers2

1

If the order is always the same you can just loop through.

foreach ($array as $key => $value) {
    if ($value[4] == 'London' && $value[5] == 1) {
        echo '$array['.$key.'] has London and 1 as key 4 and 5';
    }
}

Though you have not appointed keys to the sub-arrays, they still have default keys and you can use these to get to the values you want.

Edit

Taking a look at your array I see that there is no logic to the order of the keys. You will not be able to find the values you are looking for unless you assign keys such as town, id, date, name to them.

For example:

array(
    '0' => array(
        'name' => 'John Doe',
        'town' => 'London',
        'active' => 1,
    )

);

Peter
  • 8,776
  • 6
  • 62
  • 95
0

Use regular foreach loop to check if London value is followed by 1:

// $arr is your initial array
foreach ($arr as $k => $v) {
    if ($v[6] == 'London') {
        $hasValue = ($v[7] != 1)? "NOT" : "";
        echo "Item with key $k has 'London' which is $hasValue followed by 1". PHP_EOL;
    }
}

The exemplary output:

Item with key 0 has 'London' which is  followed by 1
Item with key 1 has 'London' which is  followed by 1
...
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105