Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP error: Uncaught TypeError: Cannot access offset of type string on string

I understand there are many similar "TypeError: Cannot access offset of type string on string" but everyone is different, and i read them. How do I skip over the nested values? We only need address_line_1, City etc.

this is the code:

foreach ($jd as $line) {
  if(!in_array($line['phone'], array_column($csv, 'phone'))){
    $newarray[sizeof($newarray)]=$line; //add unique row
    fputcsv($file, $line); //update the master csv file
  }
}

This is what some of the data looks like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

                [address_line_1] => 10860 Larry Dr, Northglenn, CO 80233
                [address_line_2] => 
                [anonymous] => 
                [blocked] => 
                [campaign_id] => o1RqNONn9jHnnBRd1M9A
                [campaign_name] => K1Keto  Camp 4/28
                [city] => Northglenn
                [company] => 
                [country] => US
                [created_date_unix] => 1656104474
                [customer_card] => Array
                    (
                    )

                [customer_group] => Array
                    (
                        [0] => Array
                            (
                                [id] => P67902g06ZfaN1O64p08
                                [name] => Prospect
                            )

                    )

                [email] => lovemyhd.ww@gmail.com
                [enabled] => 1
                [first_name] => William
                [full_address] => 10860 Larry Dr, Northglenn, CO 80233, USA
                [geocode_success] => 1
                [google_place_id] => ChIJy8IV-5p2bIcRE9IovuASaOY
                [id] => y2JWmaLGP1TdP0qoMzM5
                [internal_id] => 
                [last_name] => Wolters
                [lat] => 39.8933644
                [lifetime_value] => Array

>Solution :

Check if $line is an array before trying to index it.

if(is_array($line) && !in_array($line['phone'], array_column($csv, 'phone'))){
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading