Click here to Skip to main content
15,908,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am trying to "convert" a PHP Array to C#.

This is the PHP Array
PHP
while ($aRow = $oRes->fetchAssoc()) 
{
    if (!isset($aUsers[$aRow['movie_id']]))
    {
        $aMovies[$aRow['movie_id']] = array(
            'movie_id' => $aRow['movie_id'],
            'movie_title' => $aRow['movie_title'],
        );
    }
    if (!empty($aRow['genre_id'])) 
    {
        $aMovies[$aRow['movie_id']]['movie_genre'][$aRow['genre_id']] = array(
            'genre_id' => $aRow['genre_id'],
            'genre_name' => $aRow['genre_name']
        );
    }
}


I dont know how i should handle this, I tried using array's and list's (even Dictionary) but i cant figure it out.

any help will be appreciated.
Posted
Comments
Toli Cuturicu 11-Oct-10 17:29pm    
What programming language is that?!
Peter_in_2780 11-Oct-10 22:06pm    
@Toli. What are the first three characters of the question title?
Toli Cuturicu 12-Oct-10 3:27am    
php is a web page format, not a true programming language.
idenizeni 13-Oct-10 19:01pm    
php is not simply a web page format. http://en.wikipedia.org/wiki/PHP

1 solution

I am not into PHP but looking at the things I would suggest you create a model something like this


C#
namespace ConsoleApplication1
{
    public class Movie
    {
        // change the data types as per your needs
        public Movie(string movieId, string name)
        {
            _movieId = movieId;
            _name = name;
        }

        private string _movieId;
        public string MovieId
        {
            get { return _movieId; }
            set { _movieId = value; }
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
    }
    public class Movies :List<Movie>
    {
    }

    class Program
    {
        static void Main(string[] args)
        {
            Movies movies = new Movies(); 
            // this is how you can add information  
            // within the loop as per your need
            movies.Add(new Movie("1", "End of Days"));
            Console.ReadKey();
        }
    }
}


you can have a similar kind of model for the other array. It might be useful to override function like 'EqualsTo' in the Movie object class to be able to compare two objects.

Also, you can add find method or implement indexers in the Movies class to locate a movies based on Id or Name. There are opportunities to extend the model to cater to your needs. :)


HTH
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900