注意:数组到字符串转换将数组转换为字符串

时间:2015-02-05 18:31:11

标签: php arrays session notice

我想将所有会话的键和值转换为字符串。当我运行此代码时:

<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
$array['language'] = 'Asdfgh';
$array['currency'] = 'Asdfgh';
$array['cart'][] = 'Asdfgh';
$array['cart'][] = 'Asdfgh';
$array['facebookpagelikeshowed'] = 'Asdfgh';
$array['vid_yMHe4j2Ouko']['uid'] = '170785079';
$array['vid_yMHe4j2Ouko']['vid'] = '170785079';

    $text = '';
    foreach ($array as $key => $value)
    { 
        $text .= ''.$key.'='.$value.';';
    }
    echo $text;
?>

我收到了这个错误:

Notice: Array to string conversion in /var/www/index.php on line 16

为什么呢?我该如何解决?

1 个答案:

答案 0 :(得分:0)

问题是foreach到达$ key vid_yMHe4j2Ouko $的值是array类型,因此您无法使用concat运算符(. $value