PHP api Need to make strings

97 Views Asked by At

I have a question about how I can give each output a single string.

My code is:

try {
    $journals = new \Picqer\Financials\Exact\Journal($connection);
    $result   = $journals->get();
    foreach ($result as $journal) {
        echo 'Journal: ' . $journal->Description . '<br>';
    }
} catch (\Exception $e) {
    echo get_class($e) . ' : ' . $e->getMessage();
}

and my output is:

Journal: Kasboek 
Journal: Memoriaal
Journal: Activamutaties
Journal: Inkoopboek
Journal: Bank
Journal: Verkoopboek

I want all of the output in a different string so I can export it to my other site of the api. Something like this:

Kasboek = $1 Memoriaal = $2 etc..

Please help me to resolve this

Journal.php

<?php

namespace Picqer\Financials\Exact;

/**
 * Class Journal
 *
 * @package Picqer\Financials\Exact
 * @see https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=financialJournals
 *
 * @property String $Code BIC code of the bank where the bank account is held
 * @property Int32 $Division Division code
 * @property String $Description Description of BankAccount
 * @property Guid $ID Primary Key
 * @property String $Type Bank account number. Is mandatory for Journals that have Type = Bank
 */
class Journal extends Model
{
    use Query\Findable;
    use Persistance\Storable;

    protected $fillable = [
        'Code',
        'Division',
        'Description',
        'ID',
        'Type',
    ];

    protected $url = 'financial/Journals';
}
1

There are 1 best solutions below

4
On

When you use api. You really should convert your output into json or xml. So from any language you can read it. Change your code as below

try {
    $result = array();
    $journals = new \Picqer\Financials\Exact\Journal($connection);
    $result   = $journals->get();
    foreach ($result as $journal) {
       $result[]= $journal->Description;
    }
    echo json_encode($result);
} catch (\Exception $e) {
    echo json_encode(array(get_class($e) . ' : ' . $e->getMessage()));
}