1

我有一个关于如何给每个输出一个字符串的问题。

我的代码是:

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();
}

我的输出是:

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

我希望所有输出都使用不同的字符串,以便可以将其导出到我的其他 api 站点。像这样的东西:

Kasboek = $1 Memoriaal = $2 etc..

请帮我解决这个问题

日志.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';
}
4

1 回答 1

2

当你使用api。您确实应该将输出转换为jsonor xml。因此,您可以从任何语言阅读它。更改您的代码如下

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()));
}
于 2017-11-04T12:38:15.477 回答