Answer the question
In order to leave comments, you need to log in
How to convert null, true, ... to string?
There is an array:
You need to convert it to a string like: testnullfalsetrue
I do this, but null, false, etc. are not displayed:$data = ['test', null, false, true];
$string = '';
foreach ($data as $datum) {
$string .= (string)$datum;
// Или так:
$string .= "$datum";
}
Answer the question
In order to leave comments, you need to log in
It seems so, but maybe someone will have a better solution ..
$data = ['test', null, false, true];
$string = '';
foreach ($data as $datum) {
$string .= is_string($datum) ? $datum : json_encode($datum);
}
return $string;
According to the syntax, something is wrong, but the essence is this:
$string = '';
foreach ($data as $datum) {
switch ($datum) {
case null: {$string .= 'null'};
case false: {$string .= 'false'};
case true: {$string .= 'true'};
default: {$string.=$datum};
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question