P
P
Peter2015-01-27 15:58:06
symfony
Peter, 2015-01-27 15:58:06

How to turn a 2D array (result of fetchAll from Doctrina) into a string?

Hi
I'm tired of writing crutches, I'm sure that I just don't know something.

$foo = $app['dbs'][$bd] -> fetchAll(SELECT id FROM bar);

How can I turn the resulting array into a string?
I clarify the question: I need an analogue of implode - to present the string as 1, 2, 3 ...
Thanks

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
Igor, 2015-01-27
@hurgadan

php.net/manual/en/function.serialize.php
php.net/manual/en/function.json-encode.php Wo
n't work ?

A
Anton Shamanov, 2015-01-27
@SilenceOfWinter

For example use var_export()

V
Vyacheslav, 2015-01-27
@hedint

The problem is that the lines are different.
the array can be output by the print_r function - this is also a string.
can be translated into json - this is also a string.
You can use the built-in serialize - this is also a string.
And there is also md5, look - also a line in the output.
You can still use 5-10 pieces of all sorts of ready-made tools and still write as many of your own, but you probably need some specific format that you want to use for something.

B
BoShurik, 2015-01-27
@BoShurik

stackoverflow.com/a/10852752 DoctrineExtensions
has a GroupConcat function

entity_managers:
        default:
            dql:
                string_functions:
                    GROUP_CONCAT: DoctrineExtensions\Query\Mysql\GroupConcat

K
keltanas, 2015-01-27
@keltanas

Bringing a selection from the database to the form of a string is already the task of the presentation. So pass an array to the template, which will create a string of the desired format.
Asking the DB layer to perform presentation tasks is absurd.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question