PHP api需要创建字符串

时间:2017-11-04 12:24:29

标签: php arrays exact-online picqer-exact-php-client

我有一个关于如何为每个输出提供单个字符串的问题。

我的代码是:

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..

请帮我解决此问题

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 个答案:

答案 0 :(得分:2)

使用 api 时。您确实应该将输出转换为jsonxml。所以你可以用任何语言阅读它。更改您的代码如下

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