0

I have simple array like

Array
(
    [vaucher] => 000000000000000001ea0e0e697ac203f2420d36c54ad7b2f16c5a3e0692a11b
    [addresses] => Array
    (
        [0] => address_1
        [1] => address_2
        [2] => address_3
    )

    [received] => 2017-01-03T06:49:28.593Z
     ...
) 

and I'm trying to match address from [addresses] with address from my database but I've got Illegal string offset 'addresses'

Here is what I've trying to do

$match = false;

foreach ($total['addresses'] as $data) {
    if ($data == $order->address) {
            $match = $data;
            break;
    }
}

Why I've got illegal string offset here? I have tried with another array like on the provided SO thread and it's worked.. but this one doesn't work so it doesn't help me.

VLS
  • 445
  • 2
  • 6
  • 25
  • Does `var_dump($total);` give you the array you expect to see? – naththedeveloper Jan 03 '17 at 12:27
  • Yes, it's giving me what I've put on the question above. – VLS Jan 03 '17 at 12:28
  • Assuming none of the answers here helped? http://stackoverflow.com/questions/9869150/illegal-string-offset-warning-php – naththedeveloper Jan 03 '17 at 12:30
  • 1
    give us phpfiddle link or there is nothing to have an issue – Rahul Jan 03 '17 at 12:30
  • 2
    A shot into the dark: there is a mismatch of datatype of $match. In your first line you declared this variable as boolean and in the loop you tried to define it as array – Reporter Jan 03 '17 at 12:30
  • @reporter your shot seems correct – Alive to die - Anant Jan 03 '17 at 12:31
  • @reporter it can be like in the question with multiple addresses and I'm trying to loop over them and check if some of them match with the one from database. What is mean `mismatch of datatype`? – VLS Jan 03 '17 at 12:32
  • @VLS As I wrote: you give at first line `$match = false;`. It seems you give the variable `match` a boolean value. Within the loop you want to give `match`an Array or a String value `$match = $data`. A single equals sign is a keyword for declaration. – Reporter Jan 03 '17 at 12:36
  • Is $data contain boolean value ? – Soni Vimalkumar Jan 03 '17 at 12:39
  • @SoniVimal in my eyes not. – Reporter Jan 03 '17 at 12:39
  • @reporter that is correct. Single `=` do the trick even I still can't understand why.. I want to match them i.e. to check if is exist. – VLS Jan 03 '17 at 12:40
  • @VLS And why don't you write `$match = true;`? You code says read the value from data -an element from array Address- and give this value the boolean variable `$match`. – Reporter Jan 03 '17 at 12:42
  • I tough `$match = true;` meaning that will be true even if is false because it's true in the first place. Some misunderstanding here – VLS Jan 03 '17 at 12:45
  • can you post more of the source code? where does $total come from? – Sepultura Jan 03 '17 at 13:57
  • `$total` is curl which take json array from the url. Unfortunately I can't post the url here. – VLS Jan 03 '17 at 14:16

0 Answers0