php错误:未访问的typeerror:无法访问字符串上字符串的偏移

发布于 2025-02-10 12:20:06 字数 1876 浏览 2 评论 0原文

我知道有许多类似的“ TypeError:无法访问字符串上的字符串偏移”,但每个人都不同,我阅读了它们。如何跳过嵌套值?我们只需要地址_line_1,城市等。

这是代码:

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
  }
}

这就是某些数据的样子

                [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] => [email protected]
                [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

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

                [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] => [email protected]
                [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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木格 2025-02-17 12:20:06

在尝试索引之前,请检查$ line是一个数组。

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

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

if(is_array($line) && !in_array($line['phone'], array_column($csv, 'phone'))){
℡寂寞咖啡 2025-02-17 12:20:06

您可以尝试两件事:

is_array($ line)来查看$ line是否真的是一个数组

if(is_array($line)){...}

,并查看使用isset()的节点是否真的存在;

if (isset($line['email']) ) {....}

You can try 2 things:

is_array($line) to see if $line is really an Array

if(is_array($line)){...}

and see if the nodes really exist using the isset();

if (isset($line['email']) ) {....}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文