简体   繁体   中英

What is 'list' variable type in php?

I`m trying to use google php api client, exactly fusiontables. For creating table parameters setting this way:

$postBody = new Google_Service_Fusiontables_Table;
$postBody->setName('Test');

I also should set at least one column this way

$postBody->setColumns($columns);

But documentation says $columns should have 'list' value. What does it mean? here it is String and boolean is very clear, but what is list?

According to Google s documentation, it s request body. What the syntax? What does mean braces and how can I set $columns? request body

It looks like it is just an array of strings. List is not a PHP datatype although there is an unrelated function called list() .

A list of columns here is of type array . A column requires at least these properties:

  1. the name of the column
  2. the type of the column ("DATETIME","LOCATION","NUMBER" or "STRING")

When you use the google php api client a column is expected to be an instance of Google_Service_Fusiontables_Column

You may set the required properties directly by passing them via an array to the constructor:

new Google_Service_Fusiontables_Column(array('type'=>'STRING','name'=>'desiredColumName'));

A complete creation of a table (with 2 columns) would look like this:

//create FusionTable-instance
$table = new Google_Service_Fusiontables_Table;

//set table-name
$table->setName('myTableName');

//set required option isExportable
$table->setIsExportable('true');

//set column(s)
$table->setColumns(array(
                          new Google_Service_Fusiontables_Column(array('type'=>'STRING',
                                                                       'name'=>'columnName')),
                          new Google_Service_Fusiontables_Column(array('type'=>'NUMBER',
                                                                       'name'=>'otherName'))
                        )
                  );

//insert the table
//$service is a Google_Service_Fusiontables-instance
$result = $service->table->insert($table);

//display Id of the new FusionTable
echo $result->tableId;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM