Written by
php-style
on
on
PHP 에러 : Array to string conversion in php
PHP 에러 : Array to string conversion in php
배열 합치기 작업 중...
$list = ['hello, world'];
$list = [$list, 'who are you?', 'bye'];
After then,
echo $list;
PHP Notice: Array to string conversion in php shell code on line 1
위와 같은 에러가 나온다.
1. Solution 1
echo json_encode($list);
라고 고치면 아래와 같은 결과값이 나온다.
[["hello, world"],"who are you?","bye"]
=> 배열을 json문자열로 변환해야 한다.
2. Solution2
foreach($list as $value)
{
echo $value, "
";
}
=> 첫 번째는 배열이라 이렇게 나오게 된다..
Array
who are you?
bye
*** 아래의 경우, 배열 병합이기에, 배열에 들어있는 string을 가져올 수 없어 invalid arguments 라고 나온다.
print implode(", ", $stuff); //prints 1, 2, 3 print join(',', $stuff);
from http://kkokkoma-dev.tistory.com/179 by ccl(A) rewrite - 2021-11-29 12:00:37