Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Equivalent of C#'s "List <String>" in PHP?

Tags:

php

I'm working with an API and it is asking me to provide a List <String> value. I'm writing PHP and can only seem to find this type in C#.

Is it an array? A comma-separated string?

like image 846
Dave Kiss Avatar asked Dec 09 '11 17:12

Dave Kiss


3 Answers

PHP does not have the concept of generic types.

You can use array():

PHP

 $arr = array();  
 $arr[0] = 'foo';

equivalent in C#

List<string> arr = new List<string>(); 
arr.Add("foo"); 
like image 156
Kakashi Avatar answered Oct 05 '22 23:10

Kakashi


I guess that you can use a simple array:

$list = array('string1', 'string2', 'string3');

or

$list = array();
$list[] = 'string1';
$list[] = 'string2';
$list[] = 'string3';

etc.

Check http://www.php.net/manual/en/language.types.array.php for details.

like image 36
Frosty Z Avatar answered Oct 05 '22 23:10

Frosty Z


Is it an array?

Yes, it is

A comma-separated string?

No, it isn't

like image 34
Eugene Manuilov Avatar answered Oct 06 '22 00:10

Eugene Manuilov