如何向数组添加变量或函数值

时间:2018-04-17 15:24:58

标签: php arrays variables

我试图传递LibIds的值($ output);输出为" 1000001,1000002"到下面的代码

我想:

 function LibIds($output)
{
$rows = get_field('library_add_ids');
    if($rows)
    {
        ob_start();
        foreach($rows as $row)
        {
        echo $row['id'].',';
        }
        $output = ob_get_clean();

        echo rtrim($output, ',');
    }
}
 $res = $api->query('bibs', array(
   'id' => '1000001,1000002', 
   'fields' => 'id,updatedDate,createdDate,deletedDate,deleted,suppressed,available,lang,title,author,materialType,bibLevel,publishYear,catalogDate,country,orders,normTitle,normAuthor,locations,fixedFields,varFields'
 ));

......有效......是

    function LibIds($output)
{
$rows = get_field('library_add_ids');
    if($rows)
    {
        ob_start();
        foreach($rows as $row)
        {
        echo $row['id'].',';
        }
        $output = ob_get_clean();

        echo rtrim($output, ',');
    }
}

$res = $api->query('bibs', array(
   'id' => 'LibIds($output);', 
   'fields' => 'id,updatedDate,createdDate,deletedDate,deleted,suppressed,available,lang,title,author,materialType,bibLevel,publishYear,catalogDate,country,orders,normTitle,normAuthor,locations,fixedFields,varFields'
 ));

...第3行是问题'id' => '1000001,1000002',,不确定是否需要解析或最好的方法。 PHP新手。 感谢

0 个答案:

没有答案