-2

I'm trying to figure how to convert an array into a string but don't know how to do it. Keep saying Array to string conversion in my function table_header or function labelheader_cell. I'm trying to understand how to convert an array into string keep giving me an error.

Here is my code:

function table_header($labels, $params='')
{
    start_row();
    foreach ($labels as $label)
        labelheader_cell($label, $params);
    end_row();
}


    function labelheader_cell($label, $params="")
    {
        echo "<td class='tableheader' $params>$label</td>\n";
    }

    function view($trans)
    {
        return get_view($trans["user_no"]);
    }

    $th = array(_("Period"), _("Amount") => array('fun'=>'view'), _("Last Year"), array('insert'=>true, 'fun'=>'edit_link'), array('insert'=>true, 'fun'=>'edit'));
        table_header($th);
Magnus Melwin
  • 1,509
  • 1
  • 21
  • 32
Coliflores
  • 25
  • 1
  • several possibilities: you can implode() the array with a delimiter like `implode(',', $array)`, you could loop through the array (`for($i=0; $i – Jeff Mar 17 '19 at 02:02
  • where should i put my implode() i'm new to this array i'm still figure out array. do i need to put it at function table_header ? or labelheader_cell function?, it would display the table Period which is date that is inserted and amount with link with view and last year date which is date updated and insert array which would edit the link. – Coliflores Mar 17 '19 at 02:31

1 Answers1

2

Use the implode function:

http://php.net/manual/es/function.implode.php

you can glue each element of the array in one string.

For Example:

for the array

$a = array('p1','p2','p3','p4');

To convert it to string

$s = implode('; ',$a);

You will get:

p1; p2; p3; p4
Roldan
  • 225
  • 2
  • 14